2012年6月23日 星期六

1.驗證email 2.驗證是否有值


javascript 驗證email

function validate(form_id,email) {

var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {

alert('Invalid Email Address');
return false;
}
}

2.驗證是否有值

if(typeOf(x)=='undefined'){
alert('undefined');
}else if(typeOf(x)=='null'){
alert('null');
}

沒有留言: