Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@johnnyopao
Last active December 15, 2022 11:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save johnnyopao/86cfaa8d89e666575035 to your computer and use it in GitHub Desktop.
Save johnnyopao/86cfaa8d89e666575035 to your computer and use it in GitHub Desktop.
This validates a field for currency for dollar and cents. Ex: 42.50
<script>
lp.jQuery(function($) {
var ruleID = 'currency';
var field = 'money_field';
var message = 'Please enter a valid currency';
var rules = module.lp.form.data.validationRules[field];
$.validator.addMethod(ruleID, function(value, field) {
var valid = ( /^\d*(\.\d{0,2})?$/.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