Character Sets

Character Sets

am 13.04.2008 14:15:52 von rn5a

Assume that a TextBox is validated with the following RegEx (users can
enter any number from 1 to 9 in the TextBox):


ValidationExpression="[1-9]" runat="server"/>

As expected, any number deom 1 to 9 entered in the TextBox evaluates
to True but if I change the ValidationExpression from [1-9] to [1-10],
then only 1 evaluates to True. The rest (from 2 to 10) evaluate to
False. Why are the numbers from 2 to 10 evaluating to False? Can
someone please explain me this?

Like 1, even 0 evaluates to True when the RegEx is [1-10]. In other
words, 0 & 1 evaluate to True & the rest from 2 to 10 evaluate to
False when the RegEx is [1-10].

An earnest request - PLEASE do not suggest alternate expressions to
validate the TextBox since I know that there are other alternatives.
All I want is to understand the logic behind the working of the RegEx
[1-10] & why it doesn't allow numbers from 2 to 10..

Thanks,

Ron

Re: Character Sets

am 13.04.2008 14:33:31 von Martin Honnen

RN1 wrote:
> Assume that a TextBox is validated with the following RegEx (users can
> enter any number from 1 to 9 in the TextBox):
>
>
> > ValidationExpression="[1-9]" runat="server"/>
>
> As expected, any number deom 1 to 9 entered in the TextBox evaluates
> to True but if I change the ValidationExpression from [1-9] to [1-10],
> then only 1 evaluates to True. The rest (from 2 to 10) evaluate to
> False. Why are the numbers from 2 to 10 evaluating to False? Can
> someone please explain me this?
>
> Like 1, even 0 evaluates to True when the RegEx is [1-10]. In other
> words, 0 & 1 evaluate to True & the rest from 2 to 10 evaluate to
> False when the RegEx is [1-10].
>
> An earnest request - PLEASE do not suggest alternate expressions to
> validate the TextBox since I know that there are other alternatives.
> All I want is to understand the logic behind the working of the RegEx
> [1-10] & why it doesn't allow numbers from 2 to 10..

Regular expressions don't know about numbers, it simply knows about
characters.
[1-10]
is the range from '1' to '1' plus the character '0' so it is the same as
[01]

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Re: Character Sets

am 13.04.2008 14:43:03 von rn5a

On Apr 13, 5:33=A0pm, Martin Honnen wrote:
> RN1 wrote:
> > Assume that a TextBox is validated with the following RegEx (users can
> > enter any number from 1 to 9 in the TextBox):
>
> >
> > > > ValidationExpression=3D"[1-9]" runat=3D"server"/>
>
> > As expected, any number deom 1 to 9 entered in the TextBox evaluates
> > to True but if I change the ValidationExpression from [1-9] to [1-10],
> > then only 1 evaluates to True. The rest (from 2 to 10) evaluate to
> > False. Why are the numbers from 2 to 10 evaluating to False? Can
> > someone please explain me this?
>
> > Like 1, even 0 evaluates to True when the RegEx is [1-10]. In other
> > words, 0 & 1 evaluate to True & the rest from 2 to 10 evaluate to
> > False when the RegEx is [1-10].
>
> > An earnest request - PLEASE do not suggest alternate expressions to
> > validate the TextBox since I know that there are other alternatives.
> > All I want is to understand the logic behind the working of the RegEx
> > [1-10] & why it doesn't allow numbers from 2 to 10..
>
> Regular expressions don't know about numbers, it simply knows about
> characters.
> =A0 [1-10]
> is the range from '1' to '1' plus the character '0' so it is the same as
> =A0 [01]
>
> --
>
> =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML
> =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/- Hide quoted text -
>
> - Show quoted text -

Thanks, Martin, not only for the prompt response but also for the
precise & simple method of explaining me the logic.

Thanks once again,

Ron