-1

for a password I need to check the length and if there is as least 3 classes of characters (for a magento)

I'm using jqueryValidate for the length, I need to use this also for the password.

By special characters, I mean lower case, upper case, numbers, special characters .

How do I do that ?

this is what a have for now :

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

        }
    });
Sparky
  • 98,165
  • 25
  • 199
  • 285
Projet Sin
  • 337
  • 8
  • 20

1 Answers1

0
<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 validation provided a useful API, you can use it to create new custom rule. Hopefully, it's useful.