0

Is there any way I could validate email against case insensitive mode. I could not use (?i) since it will throw me an exception on jquery. I want examples to work not only with a@gmail.co.uk, but also a@Gmail.co.uk.

Current regex looks like this below:

[RegularExpression(@"^(?=.*?\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b)((?!gmail\.co\.uk|\.con).)*$", ErrorMessageResourceName = "EnsureValidEmail", ErrorMessageResourceType = typeof(Resources.Global.Address))]

I have tried to use this with case insensitive mode (?i):

@"^(?i)(?=.*?\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b)((?!gmail\.co\.uk|\.con).)*$"

which resulted in jquery: Uncaught SyntaxError: Invalid regular expression:

ProgLearner
  • 171
  • 2
  • 15
  • 1
    Your initial part is already case insensitive. The only part you need to make case insensitive is `gmail\.co\.uk|\.con` => `[gG][Mm][Aa][Ii][Ll]\.[Cc][Co]\.[Uu][Kk]|\.[Cc][Oo][Nn]` – Wiktor Stribiżew May 19 '17 at 09:28
  • 1
    You could double each letter with its uppercase counterpart. For example instead of `gmail`, write `[gG][mM][aA][iI][lL]` – Gawil May 19 '17 at 09:29
  • Found a good dupe, see [RegularExpressionAttribute - How to make it not case sensitive for client side validation?](http://stackoverflow.com/a/14962296/3832970) – Wiktor Stribiżew May 19 '17 at 09:30

0 Answers0