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" } });
jquery jquery-validate
jimplode
source share