密码验证 - Javascript

发布于 2024-11-04 13:44:33 字数 499 浏览 0 评论 0原文

我想验证密码字段。我尝试过以下代码,但收到消息“您的密码必须满足以下条件............”,即使我输入了正确的密码格式。

var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$/;

     if ( !re.test(rpassword) )
       {
       alert('Your password must satisfy the following. \n\n* Password should be 4 to 8 character long. \n* Password should have at least one alphabet. \n* Password should have at least one numeric value. \n* Password should  have special characters.');
       return false;
  }   

不明白这段代码有什么问题。请帮忙!!

I want to validate password field. I have tried following code, but getting message that "Your password must satisfy the following...............", even though i enter a correct password format.

var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$/;

     if ( !re.test(rpassword) )
       {
       alert('Your password must satisfy the following. \n\n* Password should be 4 to 8 character long. \n* Password should have at least one alphabet. \n* Password should have at least one numeric value. \n* Password should  have special characters.');
       return false;
  }   

Not getting what is wrong with this code. Please help !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送君千里 2024-11-11 13:44:33

您确定不想要:

if ( !re.test(rpassword.value) ) {
  // ...
}

??您说“rpassword”是对表单中密码元素的引用。如果是这样,那么你必须首先获取它的“value”属性。

Are you sure you don't want:

if ( !re.test(rpassword.value) ) {
  // ...
}

?? You say that "rpassword" is a reference to the password element in your form. If so, then you have to get its "value" attribute first.

唯憾梦倾城 2024-11-11 13:44:33

你能试试这个正则表达式吗?

/^[a-zA-Z0-9!@#$%^&*]{4,8}$/

could you try this regular expression?

/^[a-zA-Z0-9!@#$%^&*]{4,8}$/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文