JS表单数据验证的正则表达式(常用)
常用的验证方法:
checkUserNameflag=false; checkPasswordflag=false; checkPasswordAgianflag=false; checkEmailflag=false; // 用户名校验 function checkUserName() { var username = $("userNeme").value; var zz = /^[A-Za-z0-9]{6,}$/; if (!zz.test(username)) { $("userName_warn").innerHTML = " × 用户名不符合规范"; checkUserNameflag=false; } else { /*$("userName_warn").style.color='blue'; $("userName_warn").innerHTML = "√ 用户名可用";*/ showUserExist(username); checkUserNameflag=true; } } //重置提示 function resetWarn(){ $("userName_warn").innerHTML=""; $("email_warn").innerHTML=""; $("password_warn").innerHTML=""; $("Repassword_warn").innerHTML=""; } // 密码校验 function checkPassword() { var password1 = $("password").value; if (password1.length >= 6 && password1.length <= 15) { checkPasswordflag = true; $("password_warn").style.color='blue'; $("password_warn").innerHTML = " √ 密码可用 "; checkAgianMiMa(); } else { checkPasswordflag = false; $("password_warn").innerHTML = " × 密码至少为 6 个字符 "; } } function checkPasswordAgian() { var password1 = $("password").value; var password2 = $("rePassword").value; if (password1 == password2) { if (password1 == "") { $("Repassword_warn").innerHTML = " × 请输入密码 "; checkPasswordAgianflag = false; return; } $("Repassword_warn").style.color='blue'; $("Repassword_warn").innerHTML = "√ 重复输入密码正确"; checkPasswordAgianflag = true; } else { checkPasswordAgianflag = false; $("Repassword_warn").innerHTML = " × 两次密码输入不同 "; } } function checkEmail(){ //对电子邮件的验证 var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; var email=$("email").value; if(!myreg.test(email)){ checkEmailflag=false; $("email_warn").style.color='red'; $("email_warn").innerHTML = " × 邮箱格式不符合规范"; } else { checkEmailflag=true; $("email_warn").style.color='blue'; $("email_warn").innerHTML = "√ 邮箱格式正确"; } } function submitCheck(){ alert(checkUserNameflag); if(checkUserNameflag==false || checkPasswordflag==false || checkPasswordflag==false ||checkPasswordAgianflag==false || checkEmailflag==false){ return; } } function $(id){ return document.getElementById(id); }
js正则表达式--验证表单
检测手机号码:/0?(13|14|15|18)[0-9]{9}/
检测用户名:(数字,英文,汉字,下划线,中横线):/^[A-Za-z0-9_\-\u4e00-\u9fa5]+$/
密码:(数字,英文,下划线,中横线)/^[A-Za-z0-9_-]+$/
身份证:/\d{17}[\d|x]|\d{15}/
非空:/^\S+$/
IP地址:/((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))/
相关推荐
wangzhaotongalex 2020-10-20
wyq 2020-11-11
TLROJE 2020-10-26
风雨断肠人 2020-10-13
duanqingfeng 2020-09-29
rechanel 2020-11-16
cshanzhizi 2020-10-16
luofuIT成长记录 2020-09-22
phphub 2020-09-10
taomengxing 2020-09-07
MaggieRose 2020-08-19
flyingssky 2020-08-18
山水沐光 2020-08-18
jyj00 2020-08-15
AHuqihua 2020-08-09
山水沐光 2020-08-03