Skip to content

Instantly share code, notes, and snippets.

@johnbocook
Created April 29, 2015 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbocook/92fdfdd0a7079dae5c13 to your computer and use it in GitHub Desktop.
Save johnbocook/92fdfdd0a7079dae5c13 to your computer and use it in GitHub Desktop.
<script>
lp.jQuery(function($) {
var ruleID = 'zipCode'
var field = 'zip_code';
var message = 'Please enter a valid ZIP code';
var rules = module.lp.form.data.validationRules[field];
$.validator.addMethod(ruleID, function(value, field) {
var valid = /^\d{5}([\-]?\d{4})?$/.test(value);
return valid || (!rules.required && !value);
}, message);
rules[ruleID] = true;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment