Axil
Axil

Reputation: 3311

jquery validation engine REGEX for price to accept both non floating point and 1 or 2 floating point

I am trying to get the right regex for price that can accept

(valid) numbers like 1,2,100,200,2020,10000000 decimal number (1 or 2 floating point) like 1.1, 2.20, 500.45, 10000.2,

(invalid) characters like abc, etc more than 2 floating point - 2.22222, 444.444444, 222.333

currently, i have this regex but it only works with 2 floating point like 1.22, 300.33 but if its solid numbers like 1,2,3 or 1 floating point it doesnt work.

            "priceFormat":{
                "regex": /^[0-9]+\.[0-9]{2}$|[0-9]+\.[0-9]{2}[^0-9]/,
                "alertText": "* Invalid Price Format"
            },      

Upvotes: 0

Views: 717

Answers (1)

user3559349
user3559349

Reputation:

This might be what you want

/^[0-9]+(\.[0-9]{1,2})?$/

Upvotes: 1

Related Questions