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!
Asked
Active
Viewed 327 times
1
-
Regex is for pattern matching. You're not looking for any pattern - just input validation, so you should simply check that the input is in your range using `>,<,=` – Nir Alfasi Jan 24 '14 at 04:27
1 Answers
1
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 ~ 6997[0-5]\d
: 700 ~ 75976[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])$"

falsetru
- 357,413
- 63
- 732
- 636