What is the simplest regular expression to validate emails to not accept them blindly?
It's possible to write a regular expression that only accept email addresses that follow the standards. However, there are some email addresses out there that doesn't strictly follow the standards, but still work.
Here are some simple regular expressions for basic validation:
Contains a @ character:
@
Contains @ and a period somewhere after it:
@.*?\.
Has at least one character before the @, before the period and after it:
.+@.+\..+
Has only one @, at least one character before the @, before the period and after it:
^[^@]+@[^@]+\.[^@]+$
User AmoebaMan17 suggests this modification to eliminate whitespace:
^[^@\s]+@[^@\s]+\.[^@\s]+$
And for accepting only one period:
^[^@\s]+@[^@\s\.]+\.[^@\.\s]+$
^\S+@\S+$
^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$
- Only 1 @
- Several domains and subdomains