Connecting Tech Pros Worldwide Forums | Help | Site Map

Regex validation problem

Rasika WIJAYARATNE
Guest
 
Posts: n/a
#1: Jun 26 '06
([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
Guest
 
Posts: n/a
#2: Jun 26 '06

re: Regex validation problem


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" <rasikaw@gmail.com> ha scritto nel messaggio
news:1151305048.174082.75490@i40g2000cwc.googlegro ups.com...[color=blue]
> ([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.
>[/color]


Hans Kesting
Guest
 
Posts: n/a
#3: Jun 26 '06

re: Regex validation problem


> Hi.[color=blue]
>
> 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.)
>[/color]

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
Guest
 
Posts: n/a
#4: Jun 26 '06

re: Regex validation problem


> ([1-2]{0,1}[1-9]{1})|([3]{1}[0-2]{1})[color=blue]
>
> 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.[/color]

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

Hans Kesting


Closed Thread