We use the following - written by a colleague, so can't comment on any false positives etc.
^[^@ ]+@[^.@ ]+(\.[^.@ ]+)+$
&@!.* seems to be an acceptable address according to the above (or am I misreading it?).
Should the conditions for the domain name be tighter?
It's complicated ... :(
See RFC 5321 and RFC 5322, and extensions like RFC 6531 etc. for more than you really want to know about email addresses. :confused:
The simple case is that domain names should (generally) contain only the ASCII letters 'a' to 'z' (in a case-insensitive manner), the digits '0' to '9', and the hyphen ('-'), so in the example that skimble gives, the domain name !.* is
not valid. (This simple specification does not allow for non-ASCII characters in domain names or non-latin scripts, both of which are permissible). Also, there are length limitations on the domain names parts and the overall length.
A more strict regex might be:
^[^@ ]+@[0-9A-Za-Z\-]{1,62}(\.[0-9A-Za-Z\-]{1,62})+$
In addition, the hostname (including dots) should not be more than 254 characters.
However, the above regex does not validate internationalized domain names such as üñîçøðé@üñîçøðé.com, literal IPv6 addresses such as user@[IPv6:2001:db8::1] or those in non-latin scripts (I leave those as an exercise for the reader 🙂 )
Dave