![]() |
Regular expression - range of numbers
I am writing a perl program that takes the month of the year as input. I want to check the input and make sure it is a digital between 1 and 12 and if it not, keep looping until it is. Also, is it possible to check to see is the input is exactly between 1 and 12 (i.e. will accept 12 but not accept 12x)?
I have tried: while($month !~ /^(1|2|3|4|5|6|7|8|9|10|11|12)/) { print "\n Enter month: "; chomp($month = <STDIN>); } But that isn't working. Thanks in advance for the help. Ray |
I am not perl expert. You can try "/^(1|2|3|4|5|6|7|8|9|10|11|12)$/"
|
Regular Expression
Thank you very much for your response. That worked!
|
| All times are GMT -7. The time now is 06:02 AM. |