LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > CGI/Perl/Python > Regular expression - range of numbers

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2007, 07:25 AM
rjulich rjulich is offline
New Member
 
Join Date: Feb 2007
Posts: 4
Default 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
Reply With Quote
  #2  
Old 02-13-2007, 08:59 AM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
I am not perl expert. You can try "/^(1|2|3|4|5|6|7|8|9|10|11|12)$/"
Reply With Quote
  #3  
Old 02-13-2007, 09:22 AM
rjulich rjulich is offline
New Member
 
Join Date: Feb 2007
Posts: 4
Default Regular Expression

Thank you very much for your response. That worked!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:53 AM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.