Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery validation rules

  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 found 'depends' function.

I have

  $("#myForm").validate({
  ....
  rules: {
  phone1: {
    required: {
      depends: "!#pri_noPhone:checked"
    },
    number: true,
    minlength:3,
    }

It doesn't throw an error, but it still tries to validate the phone number.

  1. Under the rules: how do i make sure that email and confirmEmail are the same? I have rules, and messages separate.
like image 951
CFNinja Avatar asked Dec 23 '22 09:12

CFNinja


1 Answers

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>
like image 113
Phill Pafford Avatar answered Jan 04 '23 17:01

Phill Pafford