Skip to content

Instantly share code, notes, and snippets.

@leefish
Forked from lksedor/validate-currency.js
Last active April 1, 2018 15:40
Show Gist options
  • Save leefish/f3669f4d9c731046c8cf3bfd57151d74 to your computer and use it in GitHub Desktop.
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.
// 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");
@VC-WhitchurchA
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment