Here I come with the new quick article. In this article, I am going to explain to validate field run time using jQuery.
jQuery Validator is very useful tool to validate fields immediately using jQuery.
For Example, You want to check email exists in the database. So, you need to write validation rules which runtime check an email address.
Let’s understand below code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | $("$#id").validate({ rules: { email: { required: true, email: true, remote: { url : <post_data_url>, type: "post", data: { email: function() { return $( "#email" ).val(); } } } } } }); }); |
Here In above code, I have written .rules()
inside the .validate()
.
The remote method will work same like Ajax call. You can pass request data and URL same like Ajax request.
Further Read:
Jquery Tabs in WordPress without plugin
jQuery Shake Effect Explained
JQuery Animation Explained
That’s it.I’m hoping that you’ve found this article helpful. Don’t hesitate to use this code and post your comments if you need help. As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.