我想过滤文件上传器。它在 FireFox 中运行良好,但在 Google Chrome 中它总是显示无效文件,尽管文件是有效的。
function validate() {
var uploadcontrol = document.getElementById('<%=fileupload.ClientID%>').value;
//Regular Expression for fileupload control.
//var reg = /^(([a-zA-Z])|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpg|.jpeg|.jpe|.gif|.bmp|.png|.JPG|.JPEG|.JPE|.GIF|.BMP|.PNG)$/;
var reg = /^(([0-9a-zA-Z\^\&\'\@\{\}\[\]\,\$\=\!\-\#\(\)\%\+\~\_ ]))+(.jpg|.jpeg|.jpe|.gif|.bmp|.png|.JPG|.JPEG|.JPE|.GIF|.BMP|.PNG|.dds|.psd|.pspimage|.tga|.thm|.tif|.tiff|.yuv)$/;
if (uploadcontrol.length > 0) {
//Checks with the control value.
if (reg.test(uploadcontrol)) {
return true;
}
else {
//If the condition not satisfied shows error message.
alert("Only Images are allowed!");
return false;
}
}
} //End of function validate.