Validate fields using JQuery validation without any submit?

前端 未结 5 2022
终归单人心
终归单人心 2020-11-29 02:39

I have a HTML5 web application with numerous user-entered fields, and I would like to do some client-side validation on those fields in javascript before sending them to the

5条回答
  •  一整个雨季
    2020-11-29 03:09

    You will have to wrap your fields within a form to use the validation plugin and it's a good practice anyway. Also, you can invoke the plugin's validation programmatically and check if the form is valid by doing:

    var $form = $('#your_form'),
        validator = $form.validate({...});
    
    //validate the form
    validator.form();
    
    //check if the form is valid 
    if ($form.valid()) {
        //form is valid
    }
    

    For more options, have a look at the docs.

提交回复
热议问题