Regular expression - range of numbers

Discussion in 'CGI/Perl/Python' started by rjulich, Feb 13, 2007.

  1. rjulich

    rjulich New Member

    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.

  2. mistwang

    mistwang LiteSpeed Staff

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

    rjulich New Member

    Regular Expression

    Thank you very much for your response. That worked!

Share This Page