Regex validation problem

Discussion in 'ASP .Net' started by Rasika WIJAYARATNE, Jun 26, 2006.

  1. ([1-2]{0,1}[1-9]{1})|([3]{1}[0-2]{1})

    I am trying to validate for numbers between 1-32 which is the valid
    range using the above regex in a asp:regexpvalidator. However it
    accepts numbers 1-29 correctly but does not accept 30-32 (this is meant
    to be handled by the part of the regex after the pipe | char).

    Does anyone know why this does not work?

    Rasika.

    PS. I am unable to use the range validator in this situation.
    Rasika WIJAYARATNE, Jun 26, 2006
    #1
    1. Advertising

  2. Rasika WIJAYARATNE

    Lorenzo Guest

    Hi.

    mmm, if I were you, I'd probably use this RegEx:
    ([1-32]{1,})

    (It takes the greatest number from 1 to 32: if you write 12 it takes 12 and
    not only 1.)

    Does it work for you?

    Lorenzo


    "Rasika WIJAYARATNE" <> ha scritto nel messaggio
    news:...
    > ([1-2]{0,1}[1-9]{1})|([3]{1}[0-2]{1})
    >
    > I am trying to validate for numbers between 1-32 which is the valid
    > range using the above regex in a asp:regexpvalidator. However it
    > accepts numbers 1-29 correctly but does not accept 30-32 (this is meant
    > to be handled by the part of the regex after the pipe | char).
    >
    > Does anyone know why this does not work?
    >
    > Rasika.
    >
    > PS. I am unable to use the range validator in this situation.
    >
    Lorenzo, Jun 26, 2006
    #2
    1. Advertising

  3. Rasika WIJAYARATNE

    Hans Kesting Guest

    > Hi.
    >
    > mmm, if I were you, I'd probably use this RegEx:
    > ([1-32]{1,})
    >
    > (It takes the greatest number from 1 to 32: if you write 12 it takes 12 and
    > not only 1.)
    >


    No, it doesn't. Regex knows nothing about numbers, it only knows about
    characters. This regex means:
    characters from '1' to '3', plus '2', repeated one or more times.
    It does match "12", it also should match "112", but it doesn't match
    "29".

    Hans Kesting
    Hans Kesting, Jun 26, 2006
    #3
  4. Rasika WIJAYARATNE

    Hans Kesting Guest

    > ([1-2]{0,1}[1-9]{1})|([3]{1}[0-2]{1})
    >
    > I am trying to validate for numbers between 1-32 which is the valid
    > range using the above regex in a asp:regexpvalidator. However it
    > accepts numbers 1-29 correctly but does not accept 30-32 (this is meant
    > to be handled by the part of the regex after the pipe | char).
    >
    > Does anyone know why this does not work?
    >
    > Rasika.
    >
    > PS. I am unable to use the range validator in this situation.


    Switch the parts around:
    ([3]{1}[0-2]{1}) | ([1-2]{0,1}[1-9]{1})
    (spaces added for clarity)

    Hans Kesting
    Hans Kesting, Jun 26, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    684
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,600
    Ant...
    Nov 6, 2003
  3. Phillip Vong

    Simple Validation Problem Using Regex

    Phillip Vong, Oct 4, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    371
    Phillip Vong
    Oct 4, 2006
  4. Replies:
    3
    Views:
    716
    Reedick, Andrew
    Jul 1, 2008
  5. bnp
    Replies:
    4
    Views:
    282
Loading...

Share This Page