我已经创建了这个脚本:
function validate(f)
{
var fname="txt_nama";
var fld=document.getElementById(fname);
var fup1 = document.getElementById('file_id');
var fileName1 = fup1.value;
var ext1 = fileName1.substring(fileName1.lastIndexOf('.') + 1);
var file1 = fup1.files;
var fup2 = document.getElementById('file_foto');
var fileName2 = fup2.value;
var ext2 = fileName2.substring(fileName2.lastIndexOf('.') + 1);
var file2 = fup2.files;
var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
if(fld.value == "")
{
alert("Please enter your name");
fld.focus();
return false;
}
else if(f.txt_email.value == "")
{
alert("Please enter your email address.");
f.txt_email.focus();
return false;
}
else if (!email_re.test(f.txt_email.value))
{
alert("Invalid E-mail address.");
f.txt_email.focus();
return false;
}
else if(fup1.value == "")
{
alert("Please enter your Scan identity");
fup1.focus();
return false;
}
else if(ext1 != 'jpg' || ext1 != 'GIF' || ext1 != 'JPEG' || ext1 != 'jpeg' || ext1 != 'gif' || ext1 != 'JPG' || ext1 != 'png' || ext1 != 'PNG')
{
alert("Upload images with extention JPG, PNG, or GIF only");
fup1.focus();
return false;
}
else if(file1.size>200000)
{
alert("Max size of Scan data is 200Kb");
fup1.focus();
return false;
}
else if(fup2.value == "")
{
alert("Please enter your Photo");
fup2.focus();
return false;
}
else if(ext2 != 'jpg' || ext2 != 'GIF' || ext2 != 'JPEG' || ext2 != 'jpeg' || ext2 != 'gif' || ext2 != 'JPG' || ext2 != 'png' || ext2 != 'PNG')
{
alert("Upload images with extention JPG, PNG, or GIF only");
fup2.focus();
return false;
}
else if(file2.size>200000)
{
alert("Max size of Scan data is 200Kb");
fup2.focus();
return false;
}
else{
return true;}
}
我在文件上传验证中遇到问题,当我输入正确的文件扩展名时它仍然是错误的或仍在验证,我是否在 if-else 中犯了一些错误?
有人可以帮我吗?