Regex validation problem

R

Rasika WIJAYARATNE

([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.
 
L

Lorenzo

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
 
H

Hans Kesting

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
 
H

Hans Kesting

([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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top