本文主要为大家详细介绍了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 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();
};相关推荐:
以上就是js注册时输入合法性验证方法实例分享的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号