PercivalMcGullicuddy
PercivalMcGullicuddy

Reputation: 5533

ASP.net - RegEx Validator control not working in FireFox

Works in IE and Chrome. Can't find any help on Google. Basically, it's just checking the extension of the file selected in a FileUpload control.

Here's the code:

        <asp:FileUpload ID="FileUpload1" runat="server" Width="450" />
       <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid file type."
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.pdf|.txt|.doc|.csv|.xls|.xlsx)$" 
ControlToValidate="FileUpload1" Display="Dynamic">
</asp:RegularExpressionValidator>

Upvotes: 0

Views: 1968

Answers (2)

Simon Halsey
Simon Halsey

Reputation: 5480

The regular expression is too restrictive. I'm not sure why it works in IE & Chrome but not in Firefox. Perhaps Firefox is stripping the path of the filename?

Your reg ex is trying to match a full Windows filepath, so would fail if it the name didn't look like that, say if you used a Mac, or Linux machine or the browser pre-stripped the path from the name.

if you change it to this:

`.(pdf|txt|doc|csv|xls|xlsx)$' it only ensures the names ends with an approved extension (this just a slight improvement on what @waqas posted)

Simon

Upvotes: 1

Waqas Raja
Waqas Raja

Reputation: 10872

There are other characters in the file path in file up loader therefore, try this Regular expression instead

(.*\.(pdf|txt|doc|csv|xls|xlsx)$)

And your RegularExpressionValidator looks like

<asp:RegularExpressionValidator id="revImage" runat="server"
   ErrorMessage="Please Upload the Valid document File" Text="*" Display="Dynamic"
   ValidationExpression=
      "(.*\.(pdf|txt|doc|csv|xls|xlsx)$)"
   ControlToValidate="fileUploaderId"> </asp:RegularExpressionValidator>

Upvotes: 4

Related Questions