Regular Expressions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    #1

    Regular Expressions

    I have a text box with a max length set to 4 in my c#
    ASP.NET page.

    I wish to validate each character so that each one is a
    digit.

    I tried "\d" but this only validates the first character.

    I tried "\d{4}?" but this expects me to enter in 4
    digits. And if I enter in a 5 or 56 or 567 the validatoin
    fires.

    What kind of custom expression do I need create to allow
    any digits to be entered and not all or none!
    Valid entries
    9
    99
    999
    9999
    invalid entries
    99a9


    Thanks

    Tom

  • Eric Gunnerson [MS]

    #2
    Re: Regular Expressions

    Try

    \d+

    which means match a digit, one or more times. If you didn't have the max
    length set, you could use:

    \d{1,4}

    which means match from 1 to 4 digits.

    --
    Eric Gunnerson

    Visit the C# product team at http://www.csharp.net
    Eric's blog is at http://blogs.gotdotnet.com/ericgu/

    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Tom" <anonymous@disc ussions.microso ft.com> wrote in message
    news:0f0401c3a2 3e$620a4c60$a00 1280a@phx.gbl.. .[color=blue]
    > I have a text box with a max length set to 4 in my c#
    > ASP.NET page.
    >
    > I wish to validate each character so that each one is a
    > digit.
    >
    > I tried "\d" but this only validates the first character.
    >
    > I tried "\d{4}?" but this expects me to enter in 4
    > digits. And if I enter in a 5 or 56 or 567 the validatoin
    > fires.
    >
    > What kind of custom expression do I need create to allow
    > any digits to be entered and not all or none!
    > Valid entries
    > 9
    > 99
    > 999
    > 9999
    > invalid entries
    > 99a9
    >
    >
    > Thanks
    >
    > Tom
    >[/color]


    Comment

    Working...