C# 使用 RegularExpressionValidator 上传文件仅适用于 Firefox IE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/810541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
File Upload with RegularExpressionValidator not working with Firefox only IE
提问by Etienne
I have a FileUpload with a RegularExpressionValidator with the following Validation Expression:
我有一个带有 RegularExpressionValidator 的 FileUpload 和以下验证表达式:
^(([a-zA-Z]:)|(\{2}\w+)$?)(\(\w[\w].*))+(.gif|.jpg|.JPG|.JPEG|.GIF|.jpeg|.png|.bmp|.3dm|.3dmf|.ai|.drw|.dxf|.esp|.mng|.png|.ps|.psp|.svg|.tiff)$
This way I make sure the User only upload images. But for some reason it does not work when I use Firefox. Why is that and how can I go around the problem?
这样我确保用户只上传图片。但是由于某种原因,当我使用 Firefox 时它不起作用。为什么会这样,我该如何解决这个问题?
采纳答案by Etienne
I found the solution.....
我找到了解决方案......
(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP])$)
Enjoy!!!
享受!!!
回答by Iralda Mitro
Try this:
尝试这个:
(.*?)\.(jpg|jpeg|png|gif)$
回答by Ed Graham
An enhancement to DaDa's solution that caters for case-sensitivity:
DaDa 解决方案的增强功能,可满足区分大小写的要求:
^(.*?)\.(((j|J)(p|P)(e|E)?(g|G))|((p|P)(n|N)(g|G))|((g|G)(i|I)(f|F)))$
回答by myforums
It does not work with Firefox v3.x because it does not allow JavaScript to get full path name from the file input field and this particular regular expression expects to see full path name.
它不适用于 Firefox v3.x,因为它不允许 JavaScript 从文件输入字段获取完整路径名,而这个特定的正则表达式希望看到完整路径名。
回答by Harish Amilineni
I have got a solution to this problem:
我有一个解决这个问题的方法:
var reg = /([^\s]+(?=.(jpg|gif|png|jpeg)).)/gm;
if (reg.test(uploadcontrol) == false) {
alert("Please upload valid image formats(.jpg,.gif,.jpeg and .png)");
}