How to write a regular expression that will pass a numbers from 60 to 99?
Asked
Active
Viewed 109 times
-2
-
So, what have you tried? Did you read any regular expression documentation? – DarkDust Feb 16 '12 at 08:12
-
Just pick the 2-figures number and check if it's between 60 and 99 – Damien Pirsy Feb 16 '12 at 08:16
-
2what's wrong with `if ($i > 60 && $i < 99)`? – Gordon Feb 16 '12 at 08:16
5 Answers
7
Fairly straightforward:
/^[6-9][0-9]$/
But why are you using regex for this?

Amber
- 507,862
- 82
- 626
- 550
3
Regular expressions is a poor tool for such task. You should really drop to a numerical comparison.
But since you ask, here's how:
/^[6-9][0-9]$/
Related questions:
3
I would probably do it by checking via ($n >= 60 && $n <= 99)
, but a possible regex is:
/^[6-9][0-9]$/

Carsten
- 17,991
- 4
- 48
- 53
1
could also use an if case:
if($value >= 60 && $value <= 99) { // do stuff}

René Höhle
- 26,716
- 22
- 73
- 82

Nicholas
- 5,430
- 3
- 21
- 21