how to set validation for email in javascript


<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;

if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}

/* JavaScript: validating email address */

isValidEmail("xyz@abc.com"); // true

function isValidEmail(email) {
var emailRegex = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
return !!email && typeof email === 'string'
&& email.match(emailformat)};
};

<script language="javascript">

function checkEmail() {

var email = document.getElementById('txtEmail');
var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

if (!filter.test(email.value)) {
alert('Please provide a valid email address');
email.focus;
return false;
}
}</script>

www.codegrepper.com
www.stackoverflow.com