jQuery.validator.methods.required()
-
08-07-2019 - |
Question
my code is :
$.validator.addMethod("dateBR", function dateBR(value, element) {
return /^(?:(?:(?:0?[1-9]|1\d|2[0-8])\/(?:0?[1-9]|1[0-2]))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:(?:(?:31\/0?[13578]|1[02])|(?:(?:29|30)\/(?:0?[1,3-9]|1[0-2])))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:29\/0?2\/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26]))))$/.test(value);
}
but I want to check it only if the Element is required ... how can I do it ?
10X !!
Solution
Add a class of 'required' to your element:
<input class='required' />
Then loop through the class names with:
$(this).attr('class').split(' ');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow