Asked 30+ days ago
23 Nov 2016
Views 185
jaggy

jaggy posted

how to validate email in JavaScript ?

How to validate email in JavaScript or in jQuery ?
Mitul Dabhi

Mitul Dabhi
answered Jan 21 '18 20:16

use Regular Expression to check Email

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

use it .

var email= document.getElementById('email');
if(!emailValidator(email)){
alert("Enter Valid Email");
}
function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
 
		elem.focus();
		return false;
	}
}
Edit Answer
Share
Post Answer