Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular Expression for Amount

Tags:

regex

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

like image 210
Dinesh Avatar asked Sep 01 '26 11:09

Dinesh


1 Answers

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

http://jsfiddle.net/s2hL7/

like image 66
driangle Avatar answered Sep 03 '26 06:09

driangle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!