In the past i used a complex check that also had a list of all valid TLDs integrated. Now every time a new TLD (like .biz or .mobi) was introduced i had to update the email check routine. Too much work imho.
Based on that and the limitations of the JS RegEx engine this will result in only three issues i can perfectly live with:
- Any TLD will be accepted (e.g. email@example.com) would be a valid email
- domainEndsWithDash@domain-.com would be valid
- local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org would be valid
Here is the String prototype:
Now to validate and email you can simply do this:
Update: Modified the Regex to reject underscore characters in the domain part.
If you've read this far you might as well follow me on Twitter here.