I’m using jquery.validationengine.en.js to (custom )validate my form fields. For one field, I’m using two custom validation. I don’t want to display both the validation message for a field. It should display only one msg at a time. How to do that?
Please find the code below
Note: allzero is used by some other fields too.
"phone": {
"regex": /^[0-9]{8,15}$/,
"alertText": "* Invalid phone number"
},
"allzero": {
"regex": /([^((\+)*(0*))])/,
"alertText": "* Invalid number"
},
HTML code:
<input type="text" name="phone" id="phone" class="textBox textNormal validate[maxSize[30],custom[onlyNumberSp],custom[phonenumber],custom[allzero]]" onfocus="jQuery('#adduserform').validationEngine('attach',{Overflown:false})">
<input type="text" name="mobile" id="mobile" class="textBox textNormal validate[maxSize[30],custom[onlyNumberSp],custom[mobile],custom[allzero]]" value="" onfocus="jQuery('#adduserform').validationEngine('attach',{Overflown:false})">
Looking at the validation engine usage instructions (at https://github.com/posabsolute/jQuery-Validation-Engine), it seems it’s possible to validate a field using a custom function call (the
funcCallvalidator). So, you should be able to use a function to check both regexps one after another, and return the appropriate error message if one of them doesn’t match: