Skip to content

Instantly share code, notes, and snippets.

@dreamstarter
Last active March 27, 2024 16:24
Show Gist options
  • Save dreamstarter/9231254 to your computer and use it in GitHub Desktop.
Save dreamstarter/9231254 to your computer and use it in GitHub Desktop.
Javascript - Use a regex to check the email address input.
function checkEmail(email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (!reg.test(email)) return false;
return true;
}
Copy link

ghost commented Jun 17, 2020

Hi, Guys. I used this regex and it helped validate any emails.

^(([^<>()\[\]\\.,;:\s@"]+(.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment