views:

3864

answers:

4

I have an ASP.NET RegularExpressionValidator that checks file extensions. Is there a quick way I can tell it to ignore the case of the extension without having to explicitly add the upper case variants to my validation expression?

ValidationExpression="([^.]+[.](jpg|jpeg|gif|png|wpf|doc|docx|xls|xlsx ...
+8  A: 

Server-side, "(?i)" can be used, but this doesn't work client-side. See here for more discussion and workaround.

i.e. "...(?i)(jpg|jpeg|gif|png|wpf|..."

Marc Gravell
I can't reach that link. I actually get an 403.6... should I get worried?
PEZ
@PEZ: retried, works fine... but there are plenty of others - just search +RegularExpressionValidator +IgnoreCase
Marc Gravell
@PEZ - I'll remove the // that might confuse some browsers; sorry...
Marc Gravell
I've tried that myself already. Doesn't help. It seems the server really has a problem with my IP!
PEZ
A: 

In VisualBasic.NET, you can use the RegExOptions to ignore he case:

Dim RegexObj As New Regex("([^.]+[.](jpg|jpeg|gif))", RegexOptions.IgnoreCase)
Sebastian Dietz
Again, this doesn't work with RegularExpressionValidator
Marc Gravell
Yes, sorry, saw it too late. I should read the questions more carefully.
Sebastian Dietz
+1  A: 

According to the Regular Expression Options, this should work:

// Added LowerCase i:
ValidationExpression="(?i:[^.]+[.](jpg|jpeg|gif|png|wpf|doc|docx|xls|xlsx ...
Michael Stum
as long as it is server-side; I don't think it works client-side
Marc Gravell
+3  A: 

You can get rid of some of the duplication in that regex:

(jpe?g|gif|png|wpf|docx?|xlsx? ...
PEZ