I have this for a custom validation for a text box that accepts money:
//custom validator for money fields
$.validator.addMethod("money", function (value, element) {
return this.optional(element) || value.match(/^\$?\d+(\.(\d{2}))?$/);
}, "Please provide a valid dollar amount (up to 2 decimal places) and do not include a dollar sign.");
It seems to work, but I don't want the dollar signs allowed. Do I change it to this:
//custom validator for money fields
$.validator.addMethod("money", function (value, element) {
return this.optional(element) || value.match(/^\?\d+(\.(\d{2}))?/);
}, "Please provide a valid dollar amount (up to 2 decimal places) and do not include a dollar sign.");
Or should I just strip out the dollar sign somewhere else and not bother the user with such a trivial problem? If that's true, where should I do that?
Thanks for answering such a n00b question.
just strip out the value before you validate. it's pretty simple:
var str = [your value];
str = str.replace('$','');
No, you would change it to this..
value.match(/^\d+(.(\d{2}))?/)
These 3 characters made up the part of the regex that matched the dollar sign.
\$?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With