I just started learning JS, jQuery and HTML on the web. I have a question, and I tried to do what was said in the answers to similar questions on SO, but that will not help.
I have a password form that accepts only input that has at least 6 characters, one uppercase letter and one number. I want to show a special message for verification, which could simply formulate these conditions again.
Here is my HTML code -
<div class="password"> <label for="password"> Password </label> <input type="password" class="passwrdforsignup" name="password" required pattern="(?=.*\d)(?=.*[AZ]).{6,}"> </div>
I use JS to set up a special verification message.
Js code
$(document).ready(function () { $('.password').on('keyup', '.passwrdforsignup', function () { var getPW = $(this).value(); if (getPW.checkValidity() === false) { getPW.setCustomValidity("This password doesn't match the format specified"); } }); });
However, the user verification message is not displayed. Please help. Thank you so much in advance! :)
UPDATE 1
I changed the password pattern to (?=.*\d)(?=.*[AZ])(.{6,}) . Based on the advice of 4castle, I realized that there were several errors in my javascript, and changed them accordingly. However, a custom validation message is not yet displayed.
JavaScript:
$(document).ready(function () { $('.password').on('keyup', '.passwrdforsignup', function () { var getPW = $(this).find('.passwrdforsignup').get(); if (getPW.checkValidity() === false) { getPW.setCustomValidity("This password doesn't match the format specified"); } }); });
Again than all of you in advance!