Email validation regular expression do not work

Issue:
The dumb users copy email addresses with a space after and past to the email text box in a web form. They then found that they cannot submit the form. The email looks ok, but because there is a space behind the standard email validation regular expression declare it as wrong email.

Solution:
Standard Email validation regular expression is,
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$

Add an extra space behind the standard regular expression to support dumb users,
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z\s]{2,9})$

Resources:
http://msdn.microsoft.com/en-us/library/ms998267.aspx
http://msdn.microsoft.com/en-us/library/hs600312.aspx
http://www.regular-expressions.info/tutorial.html
http://regexlib.com/CheatSheet.aspx

Advertisements

Diganta Kumar is an experienced Technical Program Manager with a passion for technology. He has architected and developed software for over a decade for a broad range of industries. Diganta is a founder of two online IT businesses. He likes to help, mentor, and manage software development teams to improve and produce great software. He currently works as a Principal Program Manager for Microsoft. Before joining Microsoft, he was with AWS for five years, where he managed large cross-functional programs on a global scale.

Posted in ASP.NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.