5

I have a FileUpload with a RegularExpressionValidator with the following Validation Expression:

^(([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?

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
Etienne
  • 7,141
  • 42
  • 108
  • 160
  • I would check the uploaded filename to see if there is any difference between what IE is POST'ing vs Firefox as the filename. – Chad Grant May 01 '09 at 08:11
  • I've checked. No difference in pathname. Still it's a question why it's not working in Firefox. Selected answer proposes new regex expression vs. explaining what's wrong with firefox. – myforums Feb 18 '10 at 16:43

5 Answers5

14

Try this:

(.*?)\.(jpg|jpeg|png|gif)$
Iralda Mitro
  • 7,190
  • 5
  • 24
  • 29
3

An enhancement to DaDa's solution that caters for case-sensitivity:

^(.*?)\.(((j|J)(p|P)(e|E)?(g|G))|((p|P)(n|N)(g|G))|((g|G)(i|I)(f|F)))$
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
Ed Graham
  • 4,306
  • 3
  • 30
  • 30
1

I found the solution.....

(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP])$)

Link to the answer

Enjoy!!!

Etienne
  • 7,141
  • 42
  • 108
  • 160
  • That is a completely different regex than what your question's regex was validating. you can accomplish the exact same thing with a much more readable regex, like the one DaDa posted. – Chad Grant May 01 '09 at 08:30
0

I have got a solution to this problem:

var reg = /([^\s]+(?=.(jpg|gif|png|jpeg)).\2)/gm; 
if (reg.test(uploadcontrol) == false) { 
    alert("Please upload valid image formats(.jpg,.gif,.jpeg and .png)");
}
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
-1

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.

myforums
  • 191
  • 1
  • 9