jQuery validator - Decimal not validating correctly [duplicate]
Possible Duplicate:
Jquery validation - allow number without the leading zero?
I am using the jQuery validator script to validate a field to ensure their is a number entered.
The number should allow for a decimal point. If I put a number before the decimal point, the validator passes (ex. 2.5). If I don't put a number before the decimal point (ex. .5) the validator fails. I need the validator to pass even with a .5
Is it a problem with the regular expression?
// http://docs.jquery.com/Plugins/Validation/Methods/number
number: function(value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)开发者_如何学Go?$/.test(value);
}
Try using * (0 or more) instead of + (1 or more):
/^-?(?:\d*|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/
精彩评论