Validate the e-mail address with the file using regex in Javascript


I am writing a regular expression to validate an email address in JavaScript.


This is working fine. But there came an additional requirement like " In a GMAIL address we can specify the folder name along with the email id to which the mail will be delivered. For ex. [email protected] , the mail will be delivered to the folder "office" under [email protected]'s inbox.

So how can I validate that also in the above regex. The Plus symbol is not mandatory but if + is added it should be in between the other characters before @ symbol.

You can simply add the + character inside of your character class and use a negated match before the @. Note that I removed the escape sequence from the dot and moved the hyphen as the last character, or else you need to escape it and also implemented the use of the i modifier for case-insensitive matching.


Live Demo