身份证号正则
1 function isCardNo(card) 2 { 3 // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X 4 var reg = /(^d{15}$)|(^d{18}$)|(^d{17}(d|X|x)$)/; 5 if(reg.test(card) === false) 6 { 7 alert("身份证输入不合法"); 8 return false; 9 } 10 }
邮箱
1 function checkEmail(str){ 2 var re = /^[A-Za-zd]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,4}$/; 3 if (re.test(str)) { 4 alert("ok"); 5 } else { 6 alert("nope"); 7 } 8 }
用户名以及密码
/*用户名验证*/ function checkUser(){var reg=/^[a-zA-Z][a-zA-Z0-9]{3,15}$/; if(reg.test(user)==false){ userId.innerHTML="用户名不正确"; return false; } return true; } /*密码验证*/ function checkPwd(){var reg=/^[a-zA-Z0-9]{4,10}$/; if(reg.test(pwd)==false){ pwdId.innerHTML="密码不能含有非法字符,长度在4-10之间"; return false; } return true; }