javascript - 用户离开密码字段后验证密码长度

标签 javascript jquery passwords

当用户离开密码字段或按 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/

相关文章:

javascript - 未捕获的类型错误 : Cannot read property 'getContext' of null

ios - 阻止 UITextField 安全文本清除现有文本

passwords - Ansible 连接到特定 ip

javascript - Tizen 选择器触摸事件

javascript - 多功能框 multipe 关键字

javascript - 构造函数内的 img.width/height 返回零

passwords - 有没有一种安全的方式通过电子邮件以明文形式向用户发送他们的密码?

javascript - 缩小和变量名称

javascript - 在 jQuery 中将一列的内容复制到另一列

jquery - Bootstrap 4 选项卡动画