LiteSpeed Support Forums

LiteSpeed Support Forums (http://www.litespeedtech.com/support/forum/index.php)
-   CGI/Perl/Python (http://www.litespeedtech.com/support/forum/forumdisplay.php?f=22)
-   -   Regular expression - range of numbers (http://www.litespeedtech.com/support/forum/showthread.php?t=873)

rjulich 02-13-2007 07:25 AM

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

mistwang 02-13-2007 08:59 AM

I am not perl expert. You can try "/^(1|2|3|4|5|6|7|8|9|10|11|12)$/"

rjulich 02-13-2007 09:22 AM

Regular Expression
 
Thank you very much for your response. That worked!


All times are GMT -7. The time now is 06:02 AM.