栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

js注册时输入合法性验证方法

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

js注册时输入合法性验证方法

本文实例为大家分享了js正则表达式验证输入合法性的具体代码,供大家参考,具体内容如下

// 验证用户名,只允许 字母 数字 下划线 中文
//在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个字符,支持中英文、数字、减号或下划线 ");
      } 
    }
  };
}
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 /confirm/iPassword(){
  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_/confirm/iation");

  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();
  /confirm/iPassword();
  confiemPasswordAgin();
};

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/84354.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号