13

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 ... 
Chad Birch
  • 73,098
  • 23
  • 151
  • 149
flesh
  • 23,725
  • 24
  • 80
  • 97
  • 1
    You can get rid of some of the duplication in that regex: `(jpe?g|gif|png|wpf|docx?|xlsx? ...` – PEZ Jan 11 '09 at 13:14

3 Answers3

24

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|..."

Paul
  • 26,170
  • 12
  • 85
  • 119
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
2

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

Dim RegexObj As New Regex("([^.]+[.](jpg|jpeg|gif))", RegexOptions.IgnoreCase)
Sebastian Dietz
  • 5,587
  • 1
  • 31
  • 39
1

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
  • 177,530
  • 117
  • 400
  • 535