View Full Version : Fixing email validation

6 Jan 2011, 7:26 AM
Ext version tested:

Ext 3.3.0

Adapter used:

No idea (I'm just a user)

css used:

Not really relevant

Browser versions tested against:

Minefield 4.0b9pre (2011-01-05)
IE 9.0.7930.16406
Opera 11.0 (build 1156)

Operating System:

Windows 7


The email regex produce some false positive

Test Case:
Possible fix: I'm aware that perfect email verification is nearly impossible to achieve. However the email verification
should not produce false positive (which is very frustrating).

The following regex (source (http://fightingforalostcause.net/misc/2006/compare-email-regex.php)) while not perfect should produce far less (if any) false positive :

I must say that it's nice for once to see an error message stating that the email address is not recognized and not that it's invalid =D>

6 Jan 2011, 1:53 PM
## Hotmail refuses some characters ! # $ % * / ? ^ ` { | } ~
## Stated here: http://en.wikipedia.org/wiki/Email_address

The wiki also states that the IP address is surrounded by square braces. I have seen it work without it though in the past.

I'm testing the following for .../src/widgets/form/VTypes.js

email = /^[a-z0-9\-&_=+\']+(\.[a-z0-9\-&_=+\']+)*@([a-z0-9_][a-z0-9\-_]*(\.[a-z0-9\-_]+){0,4}\.([a-z]){2,6}|(\[?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\]?))(:[0-9]{1,5})?$/i,

'emailMask' : /[a-z0-9_\.\-\+\'&=@\[\]:]/i,

7 Jan 2011, 12:37 AM
IMHO we should follow RFC 2822 (see here (http://www.regular-expressions.info/email.html)).

7 Jan 2011, 8:56 AM
What are your thoughts on using this? It should work for 99.99% of the time. Taken from http://www.regular-expressions.info/email.html. Added ^, backslashed -, and changed \b to $.

Folks who need the support for an IP address with optional port number can override this.

email = /^[a-z0-9!#$%&'*+/=?^_`{|}~\-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~\-]+)*@(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?\.)+(?:[a-z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$/i

'emailMask' : /[a-z0-9!#$%&'*+/=?^_`{|}~\-\.@]/i

7 Jan 2011, 9:09 AM
Do we really want to name all those TLDs and have the regexp break when one is added?

I would have gone with the suggested regexp with the unchecked TLD.

ps. Same mistake as I made a few days ago: ^ and $ inside [] also need to be escaped.

7 Jan 2011, 9:21 AM
This one -- 2nd from last regular expression at http://www.regular-expressions.info/email.html under "The Official Standard: RFC 2822"


7 Jan 2011, 9:57 AM
Will use this. The regular express above will not catch this: hello@japan.j (at least 2 letters are needed)

email = /^[a-z0-9!#\$%&'\*\+/=\?\^_`{|}~\-]+(?:\.[a-z0-9!#\$%&'\*\+/=\?\^_`{|}~\-]+)*@(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?\.){1,5}(?:[a-z]){2,6}$/i

'emailMask' : /[a-z0-9!#\$%&'\*\+/=\?\^_`{|}~\-\.@]/i