I am trying to make a form validator that requires at least 6 characters in the input text field. It's supposed to show error if the length is less than 6 and Matched! if its more than 6. But, it's showing error no matter how long the character is.
$(function() {
let texts = $("#txt").val();
let password = $("#pass").val();
$("#frm").submit(function(e) {
if (texts.length < 6) {
$("#text-adder").text("Error");
e.preventDefault();
} else {
$("#text-adder").text("Matched!");
}
})
});
textswill always be the initial value, movelet texts = $("#txt").val();inside the event handler