0

We have a set RegEx that we follow for validating emails, which works pretty well. Though we recently discovered if an email address has a dot(.) in it, the RegEx validation will fail if the number of characters after the dot(.) are less than 3. For example:

  • test.abcd@gmail.com -> PASS
  • test.abc@gmail.com -> PASS
  • test.ab@gmail.com -> FAIL
  • test.a@gmail.com -> FAIL

Here is the RegEx:

/^[-a-z0-9#$%^&'`?{}_=+\/}{\'?]+(\.[-a-z0-9#$%^&'`?{}_=+\/}{\'?]+([a-zA-Z]{2,4})+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
flx
  • 14,146
  • 11
  • 55
  • 70
MontyNZ
  • 3
  • 2
  • 4
    You should read this answer: [Using a regular expression to validate an email address](http://stackoverflow.com/a/201378/1163867]) – MarcinJuraszek Dec 12 '13 at 02:46
  • I did, but it would be quite beneficial if I get an answers for this specific regex statment. – MontyNZ Dec 12 '13 at 02:59
  • For learning I'd recommend using this free syntax highlighter http://regex101.com/ its the best one I've tried so far. It even describes each part of the regex to you and has various regex engines available. You could probably simplify that regex using metacharacters and also you only really need to match on the tld domain and @ structure. http://www.regular-expressions.info/email.html the definitive source describes how best to do it in detail, I think it has the RFC condensed version too, which is horrible!! – JoeKir Dec 12 '13 at 03:14
  • Thanks, it's a great tool. – MontyNZ Dec 12 '13 at 03:50

1 Answers1

0

Just delete the ([a-zA-Z]{2,4})+ part of the regex near the middle. I don't see why that would even be there in the first place.

jwodder
  • 54,758
  • 12
  • 108
  • 124