Last active
June 8, 2023 17:29
-
-
Save jonkemp/9094324 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.
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 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"); |
Mechular
commented
May 28, 2019
Excellent work.
However, if I type a letter into the field by mistake, and then tab out to the next field, it fills the current field with "NaN" in addition to displaying the error message. Is there a way to keep the NaN from showing up in the text field?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment