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])
To get a valid email id we use a regular expression /^[a-zA-Z0-9.! #$%&'*+/=? ^_`{|}~-]+@[a-zA-Z0-9-]+(?:\. [a-zA-Z0-9-]+)*$/.
A global match finds all matches (compared to only the first).
\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.
This regular expression complies with the grammar described in RFC 2822, it's very long, but the grammar described in the RFC is complex...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With