Quantcast
Channel: How can I validate an email address using a regular expression? - Stack Overflow
Viewing all articles
Browse latest Browse all 89

Answer by Dimitris Andreou for How can I validate an email address using a regular expression?

$
0
0

I don't believe the claim made by bortzmeyer, above, that "The grammar (specified in RFC 5322) is too complicated for that" (to be handled by a regular expression).

Here is the grammar: (from http://tools.ietf.org/html/rfc5322#section-3.4.1)

addr-spec       =   local-part "@" domainlocal-part      =   dot-atom / quoted-string / obs-local-partdomain          =   dot-atom / domain-literal / obs-domaindomain-literal  =   [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]dtext           =   %d33-90 /          ; Printable US-ASCII                    %d94-126 /         ;  characters not including                    obs-dtext          ;  "[", "]", or "\"

Assuming that dot-atom, quoted-string, obs-local-part, obs-domain are themselves regular languages, this is a very simple grammar. Just replace the local-part and domain in the addr-spec production with their respective productions, and you have a regular language, directly translatable to a regular expression.


Viewing all articles
Browse latest Browse all 89

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>