views:

1502

answers:

7

Hi

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?

Thanks in advanced.

A: 

I found the solution.....

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

Link to the answer

Enjoy!!!

Etienne
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
+6  A: 

Try this:

(.*?)\.(jpg|jpeg|png|gif)$
DaDa
+1  A: 

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)))$

Ed Graham
A: 

Yes, DaDa's solution works perfectly fine and is MUCH more readable. Thanks very much everyone.

Jesse
A: 

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
A: 

yes. DaDa's solution working fine. i appreciate that.

Pratik
A: 

Asp.net's documentation states that the fileupload.filename property should not contain the path but only the filename. So I have the opposite problem. My code:

<asp:RequiredFieldValidator ID="req1" ControlToValidate="docFileName" Text="(Required)" runat="server" /><br />
<b>File to Upload: </b><asp:FileUpload id="docFile" runat="server" />
<asp:RegularExpressionValidator ID="regexFileUpload" runat="server" ControlToValidate="docFile" 
            Text="(Invalid: File names can only contain the following characters: A-z, 0-9, ., - and _. Spaces are converted to underscores.)" 
            ValidationExpression="^[a-zA-Z0-9\s.\-_\(\)]+$" /><br />

works fine with a legal filename in Firefox 3, but not in IE8. Apparently, IE8 is looking at the entire path and disallowing all files because the path necessarily contains : and . How can I get this code to work in IE as well?

Thanks.

-- Ned

Ned Balzer