I have a form in my web and I’m using the JQuery validation plugin. I have a ‘comment’ that I want to be NOT required (it can be empty), but has to match a specific regular expression if filled.
Using this, if the field is empty, the validation returns false (not valid), and the error is shown:
'comment':{
required: false,
regexp: /^([-a-z0-9_ ()])+$/i,
},
How can I achieve the intended behaviour?
Try:
I just added another match for emptiness