how to set validation for email in javascript

function validateform(){
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(""); // 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');
return false;