Skip to content

Instantly share code, notes, and snippets.

@lksedor
Forked from jonkemp/validate-currency.js
Last active December 5, 2016 03:53
Show Gist options
  • Save lksedor/9e009105a5b012dbb03a to your computer and use it in GitHub Desktop.
Save lksedor/9e009105a5b012dbb03a 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.
// Validation method for US 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