Dinesh
Dinesh

Reputation: 1128

regular Expression for Amount

How to set the maximum price limit(e.g. £50.00) in this regular expression?

Regular Expression: /^\£?[0-9]+.[0-9][0-9]?$/

Sample Code used for testing
Valid values:
12.55
£12.55
3.88
£0.00

Invalid values:
£12.
£12
££12
£12.445

Here I want to enforce the following rules as well.
valid: 50.00 (MAX)

Invalid: 50.99,100.00,1212221.00

How to achieve this in the above Regex?
JSFIDDLE for this is available here

Upvotes: 3

Views: 368

Answers (1)

driangle
driangle

Reputation: 11779

/^\£?((50(\.00)?)|([0-4]?[0-9](\.[0-9]{2})))$/

http://jsfiddle.net/s2hL7/

Upvotes: 3

Related Questions