regExpression Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeffery.kabir@gmail.com

    #1

    regExpression Help

    I'm trying to get a regular expression that matches only 4 digits, i'm
    using

    Regex.IsMatch(u serID, "^\d{4}")

    If the user types in more than 4 digits it still is being returned as a
    match. Should I be using IsMatch, or is my regular expression wrong?
    Thanks.

  • nikki

    #2
    Re: regExpression Help


    jeffery.kabir@g mail.com wrote:[color=blue]
    > I'm trying to get a regular expression that matches only 4 digits, i'm
    > using
    >
    > Regex.IsMatch(u serID, "^\d{4}")
    >
    > If the user types in more than 4 digits it still is being returned as a
    > match. Should I be using IsMatch, or is my regular expression wrong?
    > Thanks.[/color]

    Try
    Regex.IsMatch(u serID, "^\d{4}$")

    Comment

    • Siva M

      #3
      Re: regExpression Help

      Try "^\d{4}$"

      <jeffery.kabir@ gmail.com> wrote in message
      news:1128522035 .392642.31130@g 14g2000cwa.goog legroups.com...
      I'm trying to get a regular expression that matches only 4 digits, i'm
      using

      Regex.IsMatch(u serID, "^\d{4}")

      If the user types in more than 4 digits it still is being returned as a
      match. Should I be using IsMatch, or is my regular expression wrong?
      Thanks.


      Comment

      • jjrdk

        #4
        Re: regExpression Help

        jeffery.kabir@g mail.com wrote:[color=blue]
        > I'm trying to get a regular expression that matches only 4 digits, i'm
        > using
        >
        > Regex.IsMatch(u serID, "^\d{4}")
        >
        > If the user types in more than 4 digits it still is being returned as a
        > match. Should I be using IsMatch, or is my regular expression wrong?
        > Thanks.
        >[/color]
        Try "^\d{4}\z". I think you are forgetting to check for the end of the
        string.

        jjrdk

        Comment

        Working...