我创建了一个简单的密码确认,这将自动检查密码,如果匹配,不单击提交按钮。
如果不匹配,则禁用该按钮;如果密码匹配,则启用该按钮。
现在,有没有一种方法可以让代码检查密码中是否至少有5位数字。如果不是,它应该显示一条消息,要求他/她必须输入至少5位数字作为密码。
这是我当前用于检查密码的脚本:
<script>
$('#password, #password1').on('keyup', function () {
if (!$('#password').val()) {
$('#message').html('');
} else {
if ($('#password').val() == $('#password1').val()) {
$('#message').html('Password Match').css('color', 'green');
$('#submit').prop('disabled', false);
} else {
$('#message').html('Password not Match').css('color', 'red');
$('#submit').prop('disabled', true);
}
}
});
</script>发布于 2018-07-27 09:44:01
尝试将以下验证添加到代码中
if ($('#password').val().length < 5) {
$('#message').html('Password must be at least 5 digits').css('color', 'red');
$('#submit').prop('disabled', true);
}https://stackoverflow.com/questions/51549654
复制相似问题