jquery validation rules

后端 未结 3 1221
闹比i
闹比i 2020-12-19 15:22
  1. My phone validation depends on a checkbox (no, don\'t contact me via phone). If this is checked, then I will not need run the phone validation. I googled around and fo
相关标签:
3条回答
  • 2020-12-19 15:41

    You would use something lile this:

    $("#myForm").validate({
          rules: {
              username: {
               email: {
                    required:true,
                    email:true,
                    maxlength:255,
                },
                confirmEmail: {
                    required:true,
                    equalTo: "#email"
                },
             } 
           }
         })
    
    0 讨论(0)
  • 2020-12-19 15:45

    try something like this:

    "#phone1": {
       number: true,
       minlength:3,
       required: function(element){
          return ($('#pri_noPhone_wrapper input:checked').val() == 'True');
       }
    }
    

    The HTML (after looking at this I forgot to add the wrapper HTML)

    <span id='pri_noPhone_wrapper'>
    Phone:
    <input type="checkbox" name="pri_noPhone" value="what ever" />
    </span>
    
    0 讨论(0)
  • 2020-12-19 16:03

    I think you want your dependency specified using proper selector syntax:

    required: {
        depends: "#pri_noPhone:not(:checked)"
    }
    

    EDIT

    Steve's answer on the email:

    confirmEmail: {
        required:true,
        equalTo: "#email"
    },
    
    0 讨论(0)
提交回复
热议问题