密码验证
我正在尝试通过以下代码使用 JavaScript 验证 PHP 中的确认密码:
if($_POST['PasswordField']== $_POST['ConfirmPassword'] && $_POST['PasswordField']>='8')
{
echo "Succed <br>";
}
else
{
echo "filed <br>";
}
它可以很好地匹配两个密码,但密码的长度不起作用。但是如果我输入少于 8 个字符的密码,它就会成功 - 这是为什么?
另外,如何使用 JavaScript 但不使用正则表达式检查密码强度?
I am trying to validate confirm passwords in PHP using JavaScript by this code:
if($_POST['PasswordField']== $_POST['ConfirmPassword'] && $_POST['PasswordField']>='8')
{
echo "Succed <br>";
}
else
{
echo "filed <br>";
}
It works well with matching the two passwords, but the length of the password is not working. But if I enter a password which is less than 8 character it succeeds - why is this?
Also, how can I check password strength using JavaScript but not using Regular expressions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用 strlen() 方法来获取字符串的长度包含在 $_POST['PasswordField'] 中。并且您不应该使用字符串“8”来检查它。所以它需要像这样:
使用 POST 中的两个值调用此方法。另外,使用 trim() 去除空格。
噢...而且它与 JavaScript 无关。
You should use the strlen() method to get the length of the string that is contained in $_POST['PasswordField']. And you should not check it with a string '8'. So it needs to be like:
Call this method with the two values from your POST. Also, use trim() to strip whitespaces.
Ohw...and it has nothing to do with JavaScript.
对于密码长度,您需要使用
strlen
For password length you need to use
strlen
您需要
strlen();
函数来获取密码的长度。http://php.net/manual/en/function.strlen.php
You need the
strlen();
function to get the length of the password.http://php.net/manual/en/function.strlen.php