Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate email address using javascript

here's the code that I'm using to validate email address on clicking submit button by the user,

/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(EmailID);

I would like to allow apostrophe(') to the email address entered by the user, what would be the modification for the regex above?

like image 812
Keethan Avatar asked May 25 '26 10:05

Keethan


1 Answers

try this:

/^(\w|')+([\.-]?(\w|')+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

it will allow apostrophe anywhere before the '@'

like image 175
davidrac Avatar answered May 26 '26 22:05

davidrac