Regex empty string or email

rob waminal picture rob waminal · Feb 21, 2011 · Viewed 251.6k times · Source

I found a lot of Regex email validation in SO but I did not find any that will accept an empty string. Is this possible through Regex only? Accepting either empty string or email only? I want to have this on Regex only.

Answer

Dave Child picture Dave Child · Feb 21, 2011

This regex pattern will match an empty string:

^$

And this will match (crudely) an email or an empty string:

(^$|^.*@.*\..*$)