Regex validation problem

  • Thread starter Thread starter Rasika WIJAYARATNE
  • Start date Start date
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.
 
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
 
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
 
([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
 
Back
Top