Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Character Sets

Reply
Thread Tools

Character Sets

 
 
RN1
Guest
Posts: n/a
 
      04-13-2008
Assume that a TextBox is validated with the following RegEx (users can
enter any number from 1 to 9 in the TextBox):

<asp:TextBox ID="txt" runat="server"/>
<asp:RegularExpressionValidator ID="regexp" ControlToValidate="txt"
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-13-2008
RN1 wrote:
> Assume that a TextBox is validated with the following RegEx (users can
> enter any number from 1 to 9 in the TextBox):
>
> <asp:TextBox ID="txt" runat="server"/>
> <asp:RegularExpressionValidator ID="regexp" ControlToValidate="txt"
> 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/
 
Reply With Quote
 
 
 
 
RN1
Guest
Posts: n/a
 
      04-13-2008
On Apr 13, 5:33*pm, Martin Honnen <mahotr...@yahoo.de> 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):

>
> > <asp:TextBox ID="txt" runat="server"/>
> > <asp:RegularExpressionValidator ID="regexp" ControlToValidate="txt"
> > 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/- 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to handle different character sets with web applications? frank_ratzlow@hotmail.com Java 4 11-06-2005 10:58 AM
JSP Character Sets sonofseymour@aol.com Java 1 07-07-2005 05:23 AM
Character sets, email, and globalization (oh my!) MattB ASP .Net 0 06-14-2005 08:29 PM
character sets Robert M. Gary Java 4 03-15-2005 08:01 PM
Java Newbie Question: Character Sets, Unicode, et al BLG Java 13 10-21-2003 08:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57