Last active
December 15, 2022 11:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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