hmm strange not to see this answer already within the answers. Here is the one I've build.It is not a bulletproof version but it is 'simple' and checks almost everything.
[\w+-]+(?:\.[\w+-]+)*@[\w+-]+(?:\.[\w+-]+)*(?:\.[a-zA-Z]{2,4})
I think an explanation is in place so you can modify it if you want:
(e) [\w+-]+
matches a-z, A-Z, _, +, - at least one time
(m) (?:\.[\w+-]+)*
matches a-z, A-Z, _, +, - zero or more times but need to start with a . (dot)
@
= @
(i) [\w+-]+
matches a-z, A-Z, _, +, - at least one time
(l) (?:\.[\w+-]+)*
matches a-z, A-Z, _, +, - zero or more times but need to start with a . (dot)
(com) (?:\.[a-zA-Z]{2,4})
matches a-z, A-Z for 2 to 4 times starting with a . (dot)
giving e(.m)@i(.l).com
where (.m)
and (.l)
are optional but also can be repeated multiple times.I think this validates all valid email addresses but blocks potential invalid without using an over complex regular expression which won't be necessary in most cases.
notice this will allow +@-.com
but that is the compromise for keeping it simple.