JQuery Validate Plugin - Trigger Validation Of Single Field
Solution 1:
This method seems to do what you want:
$('#email-field-only').valid();
Edit
API has changed, see Paul's answer.
Solution 2:
Use Validator.element()
:
Validates a single element, returns true if it is valid, false otherwise.
Here is the example shown in the API:
var validator = $( "#myform" ).validate();
validator.element( "#myselect" );
.valid()
validates the entire form, as others have pointed out. The API says:
Checks whether the selected form is valid or whether all selected elements are valid.
Solution 3:
For some reason, some of the other methods don't work until the field has been focused/blured/changed, or a submit has been attempted... this works for me.
$("#formid").data('validator').element('#element').valid();
Had to dig through the jquery.validate script to find it...
Solution 4:
$("#FormId").validate().element('#FieldId');
Solution 5:
If you want to validate individual form field, but don't want for UI to be triggered and display any validation errors, you may consider to use Validator.check() method which returns if given field passes validation or not.
Here is example
var validator = $("#form").data('validator');
if(validator.check('#element')){
/*field is valid*/
}else{
/*field is not valid (but no errors will be displayed)*/
}
Post a Comment for "JQuery Validate Plugin - Trigger Validation Of Single Field"