欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js注冊時輸入合法性驗(yàn)證方法

 更新時間:2017年10月21日 09:18:38   作者:數(shù)星星的咚咚咚  
這篇文章主要為大家詳細(xì)介紹了js注冊時輸入合法性驗(yàn)證方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js正則表達(dá)式驗(yàn)證輸入合法性的具體代碼,供大家參考,具體內(nèi)容如下

// 驗(yàn)證用戶名,只允許 字母 數(shù)字 下劃線 中文
//在input元素后面增加一個span元素,提示

function confirmName(){
  var name=document.getElementById("user_name");
  name.onblur=function(){
    if((name.value).length!=0){
      reg=/^[\u4e00-\u9fa5_a-zA-Z0-9-]{1,16}$/g;
      if(!reg.test(name.value)){
        alert("對不起,輸入的用戶名限16個字符,支持中英文、數(shù)字、減號或下劃線 ");
      } 
    }
  };
}
function confirmEmail(){
  var email=document.getElementById("user_email");
  email.onblur=function(){
    if((email.value).length!=0){
      reg=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/ ;
      if(!reg.test(email.value)){ 
        alert("對不起,您輸入的郵箱格式不正確!");
      }
    }
  };
}
function confirmPassword(){
  var password=document.getElementById("user_password");
  password.onblur=function(){
    if((password.value).length!=0){
      reg=/^(\w){6,20}$/;
      if(!reg.test(password.value)){ 
        alert("對不起,您輸入的密碼格式不正確!");
      }
    }
  };
}
function confiemPasswordAgin(){
  var againpassword=document.getElementById("user_password_confirmation");

  var password=document.getElementById("user_password");
  againpassword.onblur=function(){
    // alert(againpassword.value);
      if(password.value.length!=againpassword.value.length){
      alert("密碼輸入不匹配,請重新輸入");
      }
      if(password.value.indexOf(againpassword.value)==-1){
        alert("密碼輸入不匹配,請重新輸入");
      }
    };
}
window.onload=function(){
  confirmName();
  confirmEmail();
  confirmPassword();
  confiemPasswordAgin();
};

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論