Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for price validation

Need regular expression which have:

  1. Maximum 8 digits before decimal(.) point
  2. Maximum 4 digits after decimal point
  3. Decimal point is optional

Maximum valid decimal is 8 digits before decimal and 4 digits after decimal So 99999999.9999

The regular rexpression I have tried ^\d{0,8}[.]?\d{1,4}$ is failing for 123456789 and more than this. means it is taking more than 8 digits if decimal point is not available.

Tested here : http://regexpal.com/

Many many thanks in advance!

like image 913
user2338652 Avatar asked Jul 05 '13 06:07

user2338652


1 Answers

^\d{0,8}(\.\d{1,4})?$

You can make the entire decimal optional

like image 168
digitil Avatar answered Oct 23 '22 13:10

digitil