Skip to content

Instantly share code, notes, and snippets.

View Sharuru's full-sized avatar

Sharuru Sharuru

  • Shanghai, China
View GitHub Profile
@jonkemp
jonkemp / validate-currency.js
Last active June 8, 2023 17:29
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.
// 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");