Does anyone know how I can validate a price format like the following
1.00 1200.00, but I also want to allow as 1 and 1200
$.validator.addMethod('decimal', function(value, element) {
return this.optional(element) || /^[0-9]+\.\d{1,3}$/.test(value);
}, "Please enter a correct number, format 0.00");
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$( "#myform" ).validate({
rules: {
field: {
required: true,
decimal: true
}
}
});
^ I found this code, but it still allows commas. Basically I am looking for something like is numeric without the comma.
So basically only want to allow numbers and optional decimals.
Any suggestion?
Update: So the above works, but its forcing the requirement of decimal. How to make that optional so I can do 1200 or 1200.00? Or maybe there is a way to just convert 1200 to 1200.00 ?