当用户离开密码字段或按 tab 键时,我想检查密码长度是否至少为 8 个字符。 我该怎么做?
我的密码代码如下所示。
<input type="password" name="password" id="pass1" placeholder="password"/>
最佳答案
为此使用 jquery blur
方法。
$('#pass1').on('blur', function(){
if(this.value.length < 8){ // checks the password value length
alert('You have entered less than 8 characters for password');
$(this).focus(); // focuses the current field.
return false; // stops the execution.
}
});
Fiddle for Demo
关于javascript - 用户离开密码字段后验证密码长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22323414/