I am using the following regular expression to validate email addresses in my application (Angular 2).
^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$
The validation works fine, however, its failing for email addresses that contain more than one '@
' symbol (which should be invalid). e.g.
The following emails pass the check (when they should fail):
john@subaru@ferrari.com
john@subaruferrari@.com
We are looking at modifying this pattern (and not using another pattern as this is in use in production and we do not want excessive changes) so as to accommodate the above use cases.
EDIT: Apologies everybody. Added the regex now.Although the existing answers on SO address pretty much the same situation (validating email addresses), however, I am looking just a quick modification the regex I am using.