Matching a numerical range in a regular expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    Matching a numerical range in a regular expression

    i need a regular expression between 1-12 only how can i do that?
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by smartic
    i need a regular expression between 1-12 only how can i do that?
    Hi,

    the reg exp would be something like:
    Code:
    '^[0-9 ]{1,2}$'
    Though I'm not sure of the exact syntax. The trouble with this is that it allows any 1 or 2 digit character sequence made up of 0-9. Technically speaking this would allow 0 - 99 as valid input. I would use this to start to off with and then check the input to ensure that a resulting number is not greater than 12.

    Someone else may have a better solution, but it's late and I'm just trying to help.

    The tricky part is that to a computer base 10 is simply combinations of digits between 0 and 9 and so the number twelve is ot really there it's merely a name we give to 12.

    Sorry to get all conceptual- it's late.

    Cheers
    nathj

    Comment

    Working...