[thelist] JS regex help

Edwin Horneij ed_horneij at yahoo.com
Fri Oct 8 12:19:59 CDT 2004


--- "J.J.SOLARI" <jjsolari at pobox.com> wrote:

> According to RFC2822, much more characters are allowed in the local
> part of an email address (ie. local_part at domain_part) ; in my
> understanding, these characters are: !#$%&'*+-~/=?^_`|~0-9a-z
> 
> So here is the regex I use (warning: there is a hardwrap after @):
> 
> /^[!#$%&'*+-~/=?^_`|0-9a-z]+(\.[!#$%&'*+-~/=?^_`|0-9a-z]+)*@
> [0-9a-z]+([\._-][0-9a-z]+)*\.[a-z]{2,6}$
> 
> (Though this should be correct, there seems to be a problem with the
> single quote (') with some JavaScript engines, so you may have to
> drop
> this character for the regex to work. Somebody, any clue about that?)
> 
> Still this regex is far from exhaustive as it doesn't take into
> account domain names only made up of digits, and those (yet unseen)
> address between quotes like:
> 
> "other characters <even dot / and space: .>"@example.org
> 
> And, as strange as it seems, this would be a valid address.

I don't have my copy handy, but if memory serves, the email address
validation regex in _Mastering Regular Expressions_ is around a page
long.

One of the purposes of using such a regex is to validate the format of
an email address entered into a form field by a user. Not to belabor
the obvious, but in this case the real goal is to obtain an address
that is not just correctly formatted, but which actually exists and
receives email.

Where I work we are somewhat lax about what we will allow the user to
enter in the "email" form field, and then we send an email containing
the URL of a validation page to the address furnished by the visitor.
The user's account is only activated once the user goes to that page
and clicks on the submit button of a validation form. Every so often we
purge old accounts that were never activated.




		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


More information about the thelist mailing list