JQuery authentication password validation in upper and lower case

$.validator.addMethod("validpassword", function(value, element) {
    return this.optional(element) ||
        /^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[\W]).*$/i.test(value);
}, "The password must contain a minimum of one lower case character," +
           " one upper case character, one digit and one special character..");

      

The above regex does not distinguish between uppercase and lowercase letters. What's wrong?

+3


source to share


1 answer


Remove the flag i

. This makes RegEx case insensitive . Also, stretch [\W]

up to [\W_]

.



/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[\W]).*$/i.test(value);
//                                           Remove this   ^

// Ok:
/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[\W_]).*$/.test(value);

      

+8


source







All Articles