Validate a form on Click event with validator jQuery

后端 未结 3 895
Happy的楠姐
Happy的楠姐 2021-02-10 01:55

I am using jQuery validate for validate an input. My code:

 $(\'#button\').click( function() {       
    $(\"#form\").validate({              
        rules: {         


        
3条回答
  •  鱼传尺愫
    2021-02-10 02:33

    Just add .form() to manually trigger the validation immediately (the default behavior waits for a submit event):

    $('#button').click( function() {       
      $("#form").validate({              
        rules: {
          phone: {
            required: true,
            number: true,
            rangelength: [7, 14]
          }
        }
      }).form(); 
    });
    

提交回复
热议问题