密码验证 - Javascript
我想验证密码字段。我尝试过以下代码,但收到消息“您的密码必须满足以下条件............”,即使我输入了正确的密码格式。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定不想要:
??您说“rpassword”是对表单中密码元素的引用。如果是这样,那么你必须首先获取它的“value”属性。
Are you sure you don't want:
?? 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.
你能试试这个正则表达式吗?
could you try this regular expression?