Skip to content

Instantly share code, notes, and snippets.

@frayhan32
Created September 16, 2013 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frayhan32/6578157 to your computer and use it in GitHub Desktop.
Save frayhan32/6578157 to your computer and use it in GitHub Desktop.
Email Validation
//********************************//
//********Email Validation********//
//********************************//
//***************************************************//
//********Plese read instruction before using********//
//***************************************************//
//*This is simple email validation function accept one arguments using regular expression*//
//*if you havent understand about regular expression you can visit w3school or googling*//
//*Useful when deal with form integratin particulary when filling email requirement*//
//*i related to trim function so e.g when focusout the val of email no cointains space*//
//*if you havent see my trim function refere this link *//
//*https://gist.github.com/frayhan32/6568660*//
function validEmail(eMail){
if(/^.+@\w+\.(?:\w{3}|\w{2,3}\.\w{2})$/.test(trim(eMail))==true){
//code when goes right
return true;
}else{
//or false
return false;
}
}
//*Test him*//
console.log(validEmail('frayhan32@gmail.com')); //output true
console.log(validEmail('frayhan32@yahoo.co.id')); //output true
console.log(validEmail('frayhan32@net.id')); //output true
console.log(validEmail('frayhan32@ne')); //output false
console.log(validEmail('frayhan32@net.ido')); //output false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment