First, add this code to validate.js (if you can't find the file, don't even do this!) I'm not an expert on JavaScript, so I hacked and bashed the comma's and all that.
- Code: Select all
['validate-phone', 'Please enter a valid US Phone Number. (xxx)xxx-xxxx', function(v) {
return Validation.get('IsEmpty').test(v) || /^(\()?(\d{3})([\)-\. ])?(\d{3})([-\. ])?(\d{4})$/.test(v)
}],
['validate-postal', 'Please enter a valid US zip code or Canadian postal code.', function(v,elm) {
v = v.toUpperCase();
var regex = /((^\d{5}([- |]\d{4})?$)|(^[A-Z]\d[A-Z][- |]\d[A-Z]\d$))/;
if(Validation.get('IsEmpty').test(v) || regex.test(v)){
$(elm).value = v;
return true;
}
return false;
}],
In the back end, pick Validate "Yes" from the validation tab. Use "Prototype" as this will cause validate.js to call in the HEAD.
Next, don't put any fields in the Validation tab. For some reason, it screws it up. Use class="validate-postal" and class="validate-phone" and the other old-school ways to call validation.
Someone might prove me wrong on some of this. I haven't spent the time to completely test all the scenarios. It's working nicely for me following these rules.
Hope this saves someone some time. I sure wish someone would add phone and postal validation to the Validation tab. Not me!
