Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be a globally accepted regular expression to match e-mail addresses

I have seen many examples, with many 'no, you missed something' comments. What is the right way to match an e-mail address?

For Sanity sake, only fully-qualified domain names, no @localhost allowed. (or, both ways)

Subdomains must be allowed ([email protected])

like image 686
Issac Kelly Avatar asked Oct 17 '08 02:10

Issac Kelly


People also ask

What is a good regular expression to match a email?

To get a valid email id we use a regular expression /^[a-zA-Z0-9.! #$%&'*+/=? ^_`{|}~-]+@[a-zA-Z0-9-]+(?:\. [a-zA-Z0-9-]+)*$/.

What is global match in regex?

A global match finds all matches (compared to only the first).

What is the regular expression for address?

\s(\b\w*\b\s){1,2}\w*\. This allows 1-5 digits for the house number, a space, a character followed by a period (for N. or S.), 1-2 words for the street name, finished with an abbreviation (like st. or rd.). to allow for a dash but not require one.


1 Answers

This regular expression complies with the grammar described in RFC 2822, it's very long, but the grammar described in the RFC is complex...

like image 164
Christian C. Salvadó Avatar answered Sep 26 '22 01:09

Christian C. Salvadó