Question

What would be a proper syntax to write a regex expression that limits a user from entering only integer numbers between a range of: 15 and 764 Thanks in advance!

Was it helpful?

Solution

Use following regular expression

^(1[5-9]|[2-9]\d|[1-6]\d\d|7[0-5]\d|76[0-4])$
  • 1[5-9]: 15 ~ 19
  • [2-9]\d: 20 ~ 99
  • [1-6]\d\d: 100 ~ 699
  • 7[0-5]\d: 700 ~ 759
  • 76[0-4]: 760 ~ 764

Escape \ if you use the pattern inside string literal.

"^(1[5-9]|[2-9]\\d|[1-6]\\d\\d|7[0-5]\\d|76[0-4])$"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top