how to validate for money in jquery
With jQuery validation plugin you can set your own rule using Jack's regular expression (which I haven't tested though) like this:
jQuery.validator.addMethod(
"money",
function(value, element) {
var isValidMoney = /^\d{0,4}(\.\d{0,2})?$/.test(value);
return this.optional(element) || isValidMoney;
},
"Insert "
);
Then you can set the rule within using the validate method:
$("#myForm").validate({
rules: {
nameOfMyInputField: {
money: true,
}
}
});
You can do this with a regular expression: /^\d{0,4}(\.\d{0,2})?$/
EDIT:
Here's the requested fiddle