Asked 8 years ago
23 Nov 2016
Views 1283
jaggy

jaggy posted

how to validate email in JavaScript ?

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

Mitul Dabhi
answered Nov 30 '-1 00:00

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;
	}
}
Post Answer