Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery regex validation: unsigned integer or float (max 2 decimal), only dot, not comma

Tags:

jquery

regex

I'm in trouble: i need a regex that match this

VALID:

3
44
55.5
66.66
777

NOT VALID:

3,3
.4
.55
-7

The regex must validate only unsigned integer or float, only dot (not comma), max 2 decimal.

like image 769
Johan Avatar asked Aug 12 '26 19:08

Johan


1 Answers

You could try the below,

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

^ Asserts that we are at the start. $ asserts that we are at the end. Basically anchors are used to do an exact string match. \d{1,2} matches one or two digits.

DEMO

like image 66
Avinash Raj Avatar answered Aug 15 '26 10:08

Avinash Raj