开发者

jQuery validator - Decimal not validating correctly [duplicate]

This question already has answers here: Closed 11 years ago.

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+)?$/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜