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: