JQuery Validate Plugin - checking a trigger for a single field

I have a form that can be pre-filled through a facebook connection. When a user connects, their name and email address are automatically populated. The problem is that it does not initiate remote confirmation to check if mail already exists.

Is there a way that I could call validation only in this field? Something like:

$('#email-field-only').validate()

would be an idea. Searched through documents without any luck.

+66
jquery jquery-validate validation
Apr 29 '10 at 16:16
source share
7 answers

This method seems to do what you want:

 $('#email-field-only').valid(); 
+121
Mar 03 2018-11-11T00:
source share

For some reason, some of the other methods do not work until the field has been focused / changed / changed or an attempt to send has been made ... this works for me.

 $("#formid").data('validator').element('#element').valid(); 

Had to break through jquery.validate script to find it ...

+14
Aug 07 2018-12-12T00:
source share
 $("#FormId").validate().element('#FieldId'); 
+8
May 24 '15 at 18:22
source share

Use Validator.element() :

Checks one element, returns true if it is valid, false otherwise.

Here is an example shown in the API:

 var validator = $( "#myform" ).validate(); validator.element( "#myselect" ); 

.valid() confirms the entire form as others have pointed out. API says:

Checks if the selected form is correct or all selected items are valid.

+8
Aug 21 '15 at 17:22
source share

When setting up validation, you must save the validator object. you can use this to check individual fields.

 <script type="text/javascript"> var _validator; $(function () { _validator = $("#form").validate(); }); function doSomething() { _validator.element($('#someElement')); } </script> 

- cross text with a similar question

+5
May 05 '11 at 21:35
source share

If you want to check a separate form field, but do not want to display validation errors to start the user interface, you can use the Validator.check () method, which returns if this field passes the check or not.

Here is an example

 var validator = $("#form").data('validator'); if(validator.check('#element')){ /*field is valid*/ }else{ /*field is not valid (but no errors will be displayed)*/ } 
+2
Feb 08 '17 at 12:21
source share
 $("#element").validate().valid() 
-6
Mar 14 2018-12-12T00:
source share



All Articles