Jquery Validation Plugin: How To Check If An Element Is Valid?
A little bit of context: I'm using the jQuery Validation plugin to validate a sign-up form. I now want to implement an ajax call to check whether the user name is available in the
Solution 1:
$("#userName").keyup(function () {
if ($("#userName").valid() == true ) {
//make ajax called
}
});
http://docs.jquery.com/Plugins/Validation/valid
Note: To those who do not click the link. You have to call $("#myform").validate();
first.
Solution 2:
Validator.element()
Description: Validates a single element, returns true if it is valid, false otherwise.
Solution 3:
This worked for me on JQuery 1.11
$("#userName").keyup(function () {
if ($(this)[0].validity.valid) {
// AJAX here
}
});
Solution 4:
Hello i find exclusive solution, i have the same problem as 47k others & i discover the solution without other jquery plugins or libraries: -first of all we need to register our input in a variable, -then on change checkValidity() if true:mean if valid we assign the registered var to our input to rest it for next change.
ivar=$('input[name="y-i-name"]')[0];
$('input[name="y-i-name"]').on('change',function(){
if($('input[name="y-i-name"]')[0].checkValidity()){
// your custom code here!
$('input[name="y-i-name"]')[0]=ivar; // & now we rest the input for next change validation
}
});
Post a Comment for "Jquery Validation Plugin: How To Check If An Element Is Valid?"