-
-
Save leefish/f3669f4d9c731046c8cf3bfd57151d74 to your computer and use it in GitHub Desktop.
Currency validation method for the jQuery Validation plugin. Decimal place is optional but if included, it requires 2 places. Also, the dollar sign is optional. EDIT: Original gist did not work with $ sign being optional. This gist adds the optional functionality for dollar, euro and pound.
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
// Validation method for variable currency | |
$.validator.addMethod("currency", function (value, element) { | |
return this.optional(element) || /^(?:(\$|€|£))?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/.test(value); | |
}, "Please specify a valid amount"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍