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 Andy Lester for How can I validate an email address using a regular expression?

$
0
0

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^\S+@\S+\.\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of getting common simple errors.

There are any number of changes that can be made to that regex (and some are in the comments for this answer), but it's simple, and easy to understand, and is a fine first attempt.


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>