I added a custom validation method to jQuery Validation such as:
$.validator.addMethod('myregex', function (value) {
return /d/.test(value);
}, 'Please enter a valid input.');
Note that I know there is a build in number check. That is just an example, I actually want to use more custom regex validators.
The problem is that now the field form is always required. Even if I set the value required to false in the code such as:
$("form[name='my-form']").validate({
// Specify validation rules
rules: {
form-field: {
required: false,
myregex: true
},
I want my regex to check if the data entered on a field is valid, but not force the field to be completed as its optional.