【问题标题】:password and confirm password validation密码并确认密码验证
【发布时间】:2015-04-03 15:18:04
【问题描述】:

我想验证密码并确认密码字段。已经完成密码不匹配的验证。现在我要验证,用户必须输入 8 到 15 之间的密码以及混合符号、字符、数字

<form id="form" action="" method="post">
<label for="pass">Password</label>
<input type="password" id="pass" class="text" name="your_pass" value="" onblur="passchk()"/>
<label for="c_pass">Confirm Password</label>
<input type="password" id="c_pass" class="text" name="your_c_pass" value="" onblur="confirmPass()"/><br>
<span id="error" style="color:#F00;"> </span>

JS:

function confirmPass() {
    var pass = document.getElementById("pass").value
    var confPass = document.getElementById("c_pass").value
    if(pass != confPass) {
        //alert('Wrong confirm password !');
        document.getElementById('error').innerHTML='wrong confirm password';
    }
    else
    {
        document.getElementById('error').innerHTML='';
    }
}


function passchk(){
    alert('hi');

}

【问题讨论】:

  • 你有没有尝试过?有几十个关于密码验证的问题,用完全开发的正则表达式字符串很好去
  • 为什么密码有 15 个字符的限制?这是不必要的限制,通常表明您以不安全的方式存储密码。

标签: javascript jquery validation passwords


【解决方案1】:

8 到 15 个字符,仅包含字符、数字、下划线和第一个字符必须是字母

function CheckPassword(input)   
{   
    var pass=  /^[A-Za-z]\w{8,15}$/;  
    if(input.value.match(pass))   
    {     
        return true;  
    }  
        else  
    {   
        alert('Password Is Not Valid')  
        return false;  
    }  
}

【讨论】:

  • 它只接受字母表中的 8-15...输入数字和符号时显示错误消息
  • ^[\w\d]{8,15}$ 试试这个,或者如果你想让你的密码以字母开头而不是试试这个 ^[A-Za-z][\w \d]{8,14}$
  • 我想要混合密码组合。像 EX:dere@12
  • ^[A-Za-z].{8,14}$ - 第一个字符必须是字母,而不是任何你想要的,阅读正则表达式手册,自己定制会很有帮助。 regexr.com - 学习和测试的好网站
  • 是的....但是我所期望的不存在....密码的多个组合(gdg@87D)。它允许用户输入完整的字母或数字
猜你喜欢
  • 2023-02-23
  • 1970-01-01
  • 1970-01-01
  • 2015-05-18
  • 1970-01-01
  • 2013-09-18
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多