Jassery validation plugin for bassistance - dependency mismatch

I was looking for stack overflow and cannot find the answer to my question.

I use the jQuery bassistance validation plugin and it works well, with the exception of one specific section, custom methods.

Methods work, it's just a call to $ ('selector'). valid () tells me that the element is not valid, although it must be valid.

This is because this.optional (element) returns a "dependency mismatch".

My question is:

What does dependency mismatch mean when checking an optional item?

Does dependency mean that it is optional but has other dependencies?

So, should my custom method check the optional field for dependency-mismatch?

I don’t understand what might come back and why.

should my custom method also return dependency mismatch? or should i handle this ??

This is my own method:

$.validator.addMethod( "ukphonenumber", function (value, element, validate) { if (validate) { var regexp = "\\s*\\(?((\\+0?44)?\\)?[ \\-]?(\\(0\\))|0)((20[7,8]{1}\\)?[ \-]?[1-9]{1}[0-9]{2}[ \\-]?[0-9]{4})|([1-8]{1}[0-9]{3}\\)?[ \\-]?[1-9]{1}[0-9]{2}[ \\-]?[0-9]{3}))\\s*"; var re = new RegExp(regexp); return this.optional(element) || re.test(value); } else { return true; } }, "Please check your input." ); 

And this adds a rule to my input:

 $("#<%=txtTelephoneNumber.ID %>").rules("add", { required: false, ukphonenumber: true, messages: { required: "Please enter your telephone number", ukphonenumber: "Your telephone number is invalid" } }); 
+6
jquery jquery-validate
source share
2 answers

I also emailed the library developer and received this answer: what solved the problem.

are there any reasons to use: false instead of the required one: true? If the field is not required, leave the required rule, instead of setting it to false.

You can also try not to call this.optional (element) as part of your custom method.

Relationship jorn

+1
source share

it works:

 return (this.optional(element) != false) || re.test(value); 

Dependency Mismatch with Jquery Validate Plugin

-one
source share

All Articles