sarsnake
sarsnake

Reputation: 27733

Javascript 2 decimals regex

I need to find a regex that will match up to 2 decimals, so:

are a match

are not a match

Upvotes: 0

Views: 435

Answers (3)

sarsnake
sarsnake

Reputation: 27733

Someone wrote in the comments and I used this one: /^[0-9]+(\.[0-9]{1,2})?$/

Upvotes: 0

dmarges
dmarges

Reputation: 361

(^[0-9]+|^[0-9]+.)([0-9]{0,2})

The above expression will match a number to 2 decimal places. I have tested this in PHP and TextWrangler.

Upvotes: 1

Adam Zalcman
Adam Zalcman

Reputation: 27243

Check out www.regular-expressions.info. The examples section in particular is something you should have a look at.

Upvotes: 0

Related Questions