Py学习  »  Jquery

如何检测jquery中的特殊字符数

Projet Sin • 6 年前 • 300 次点击  

对于密码,我需要检查长度以及是否至少有3类字符(对于magento)

我使用jqueryvalidate作为长度,我还需要将其用于密码。

我所说的特殊字符是指小写、大写、数字、特殊字符。

我该怎么做?

这就是A现在所拥有的:

    $('#form').validate({
        rules : {
            "password" : {
                minlength : 8,
                required : true
            },
            "email" :{
                required: true,
                email: true
            }

        }
    });
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38188
文章 [ 1 ]  |  最新文章 6 年前
Tan Nguyen
Reply   •   1 楼
Tan Nguyen    7 年前
<script>
  jQuery.validator.addMethod('specialChars', function(value, element, num) {
    var specialChars = value.replace(/[A-Za-z0-9 ]/g, '');
    return this.optional(element) || specialChars.length > num;
  }, 'At least {0} special chars are required');

  $("form").validate({
    rules: {
      password: {
        specialChars: 3,
        required: true,
      }
    }
  });
</script>

jquery验证提供了一个有用的API,您可以使用它来创建新的自定义规则。希望它有用。