Results 1 to 6 of 6

Thread: [RESOLVED] RegEx Question

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Resolved [RESOLVED] RegEx Question

    (([0])?[1-9])|[1][0-2]

    This will allow any digit 1 through 9 and also allow it to lead with a zero. I run into a problem when I try to do 10, 11 and 12. Those cases are the ones I specified right of the alteration character (atleast, I thought?).

    What am I doing wrong, why doesn't that match? Since it's an alteration, I figured it would work just like an "or" and ignore everything on the left. Am I missing something obvious?

    Edit:

    I just tried:
    (([0])?[1-9])|1[0-2]
    Same problem...

  2. #2

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: RegEx Question

    The expression I'm using now is:

    ((0)?[1-9])|(1[0-2])

    ((0)?[1-9]) will validate 1-9 with an optional leading zero
    (1[0-2]) will validate 10-12

    When I use the full expression with |, it only validates the left half.

    The alteration is deffinitely the problem. Anyone know what I'm doing wrong?

    Edit: I tested the two halves, they work individually.

  3. #3

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: RegEx Question

    Ok, someone's gotta know what I'm doing wrong.

    Rep points avaliable as always, please help me out.

  4. #4

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: RegEx Question

    *throws hands up in the air*

    Ok, I give up. I'll just do a nasty run-on validation function instead of any client-side validation. I'm running out of time.

    Thanks anyway.

  5. #5
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: RegEx Question

    try this
    (^0?[1-9]$)|(^1[0-2]$)

  6. #6

    Thread Starter
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: RegEx Question

    Worked, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width