An alternative would be to place your regexp in non-capturing parentheses. Then make that expression optional using the ?
qualifier, which will look for 0 (i.e. empty string) or 1 instances of the non-captured group.
For example:
/(?: some regexp )?/
In your case the regular expression would look something like this:
/^(?:[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+)?$/
No |
"or" operator necessary!
Here is the Mozilla documentation for JavaScript Regular Expression syntax.