Character Sets

Discussion in 'ASP .Net' started by RN1, Apr 13, 2008.

  1. RN1

    RN1 Guest

    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
    RN1, Apr 13, 2008
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Apr 13, 2008
    #2
    1. Advertising

  3. RN1

    RN1 Guest

    On Apr 13, 5:33 pm, 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):

    >
    > > <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
    RN1, Apr 13, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MattB
    Replies:
    0
    Views:
    338
    MattB
    Jun 14, 2005
  2. BLG
    Replies:
    13
    Views:
    1,021
    John C. Bollinger
    Oct 21, 2003
  3. Robert M. Gary

    character sets

    Robert M. Gary, Mar 15, 2005, in forum: Java
    Replies:
    4
    Views:
    407
    Mark Thornton
    Mar 15, 2005
  4. JSP Character Sets

    , Jul 6, 2005, in forum: Java
    Replies:
    1
    Views:
    435
    Ray in HK
    Jul 7, 2005
  5. Replies:
    4
    Views:
    407
Loading...

Share This Page