JQuery check if input is not empty
Good day. Help Install the Validate plugin to update your user profile. There are two input fields: "new password"
and "repeat new password"
.
Needed if they are both empty, it does not perform any checks. And if something is entered in "Password", the password is checked for validity and equality of the second password.
I've tried something like this, but this "if" doesn't work.
$.validator.setDefaults({ ignore: ":hidden:not(select)" });
$('#contact-form').validate({
rules: {
if(passord.lenght){
password: {
minlength: 6,
maxlength: 25,
required: true,
loginRegex: true
},
password_repeat: {
minlength: 6,
maxlength: 25,
required: true,
loginRegex: true,
equalTo: "#password"
}}
},
});
I searched for an answer in similar threads but couldn't find it.
+3
source to share
2 answers
Can you try this:
<form id="formCheckPassword">
<input type="password" class="form-control" name="password" id="password"/>
<input type="password" class="form-control" name="cfmPassword" id="cfmPassword" />
<input type="submit" value="submit"/>
</form>
$("#formCheckPassword").validate({
rules: {
password: {
required: true,
minlength: 6,
maxlength: 10,
} ,
cfmPassword: {
equalTo: "#password",
minlength: 6,
maxlength: 10
}
},
messages:{
password: {
required:"the password is required"
}
}
});
+2
source to share