您好,登錄后才能下訂單哦!
常用的驗證方法:
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 = " × 用戶名不符合規(guī)范"; 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 = "√ 重復(fù)輸入密碼正確"; 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 = " × 郵箱格式不符合規(guī)范"; } 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正則表達(dá)式--驗證表單
檢測手機(jī)號碼:/0?(13|14|15|18)[0-9]{9}/
檢測用戶名:(數(shù)字,英文,漢字,下劃線,中橫線):/^[A-Za-z0-9_\-\u4e00-\u9fa5]+$/
密碼:(數(shù)字,英文,下劃線,中橫線)/^[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))/
以上所述是小編給大家介紹的JS表單數(shù)據(jù)驗證的正則表達(dá)式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對億速云網(wǎng)站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。