-2

I'd like to check number what it is decimal [17, 2] (0~17 and 0~2).

What is the regular expression for a decimal [17,2]?

For example

1
0.01
0.1
12345678901234567.01
...

I used var regexp = /^\d+(?:\.\d\d?)?$/; but it can be over 17.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
kbin0505
  • 170
  • 1
  • 11

1 Answers1

1

Indeed, your regex doesn't include the 17 limit anywhere.

The regex for "0 to 17 digits" will be:

\d{0,17}

You can read more on repetitions here: https://www.regular-expressions.info/repeat.html

GaloisGirl
  • 1,476
  • 1
  • 8
  • 14