Skip to content

Instantly share code, notes, and snippets.

@lksedor
lksedor / validate-currency.js
Last active December 5, 2016 03:53 — forked from jonkemp/validate-currency.js
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");