Link to home
Start Free TrialLog in
Avatar of maratg
maratg

asked on

RegularExpressionValidator fires incorrectly in Firefox 3.0 and Safari

I'm writing a vs.net 2005 web application.  I'm asking users to upload an image file, using the asp:FileUpload element.  I have a RegularExpressionValidator that checks the path of the uloaded file to determine if it's an image based on the file extension.

Here is the code for the validator:

 <asp:RegularExpressionValidator ID="CustomValidator1" runat="server" ErrorMessage="*"
                                            ControlToValidate="elementthumbnailupload" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.jpeg|.JPEG|.bmp|.BMP|.png|.PNG)"></asp:RegularExpressionValidator>

It works well in IE, however it fires incorrectly in Firefox 3.0 and Safari (the file has the correct image extentsion).  Please help. Thanks in advance.
Avatar of graye
graye
Flag of United States of America image

That's a bit odd... since the validator is supposed to only use the "client side" portion if it detects a compatible browser.

I guess you could turn off the "client side" feature...  by using EnableClientScript = False

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.enableclientscript.aspx
Avatar of maratg
maratg

ASKER

Thanks, but this does not address the core issue as to why the validator is behaving differently in different browsers.  Although we may try to use your solution in the interim.
Are you sure your regular expression is correct? I tested it in Firefox and Internet Explorer 7.0. Although IE7 allowed the postback and didn't fire the validator, the page didn't pass server-side validation and the error text displayed after the postback.

I suspect the behaviour you are seeing in Firefox and Safari is actually the correct one.
ASKER CERTIFIED SOLUTION
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maratg

ASKER

NazoUK,
thanks, that worked like a charm.