Clear jQuery validation error message on dropdown value change
I have a dropdown that has two options 1 and 2 .
On selecting 1, there is a foundation validator that is being registered for numeric character check.
Now, if I select option 2 from dropdown, the above validation still exist and I'm not able to save the dialog.
How can I deregister this jQuery validation on dropdown value change?
jQuery code for validation is like this -
(function($, _$document) {
"use strict";
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
selector: "[.showing data-validation=data-sku-numeric-validation]",
validate: function(el) {
var expectedLength = 9;
var value = el.value.trim();
if (!value.match(/^\d+$/) && !value.match(/\s/)) {
return "Please enter only numeric values with no white spaces.";
}
if (value.length !== expectedLength) {
return "The field must be exactly " + expectedLength + " numeric characters with no white spaces.";
}
}
});
})($, $(document));