Regular Expression Question

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

    #1

    Regular Expression Question

    I hope this is an appropriate group for this question - if not, let me know
    where I should take this question.

    I want a regular expression that will validate a date in the format
    mm/dd/yyyy. I actually want to verify that the date is between 1/1/1900 and
    1/1/1960 but I cannot get past the basic validation of the date. I am using
    the validator at

    and when I enter data such as "6/" it fails The regex fragment I am using is
    "(0?[1-9]|1[012])[- /.]". The problem is in the [- /.] clause. In searching
    the web, this looks as if it should work. What am I missing?

    Wayne


  • dkode

    #2
    Re: Regular Expression Question

    If all you want to do is verify that the date is between two dates is
    to use the CompareTo function of DateTime class.

    heres a link to the docs:

    http://msdn.microsoft.com/library/de...aretotopic.asp

    when you use compareto it returns less than zero, zero or greater than
    zero to show if the date is before, equal to or after the specified
    date. No need to use a regex here

    Comment

    • Peter Macej

      #3
      Re: Regular Expression Question

      > The problem is in the [- /.] clause. In searching

      If I understand, you want to match one of the following characters -, /,
      .. as date delimiters. You need to escape at least the "." because "." is
      used in regex as "any character". It works with [\- \/\.]


      --
      Peter Macej
      Helixoft - http://www.vbdocman.com
      VBdocman - Automatic generator of technical documentation for VB, VB
      ..NET and ASP .NET code

      Comment

      • Wayne Wengert

        #4
        Re: Regular Expression Question

        Thank you. I'll give that a try.

        Wayne

        "dkode" <dkode8@gmail.c om> wrote in message
        news:1141912627 .011966.110050@ i39g2000cwa.goo glegroups.com.. .[color=blue]
        > If all you want to do is verify that the date is between two dates is
        > to use the CompareTo function of DateTime class.
        >
        > heres a link to the docs:
        >
        > http://msdn.microsoft.com/library/de...aretotopic.asp
        >
        > when you use compareto it returns less than zero, zero or greater than
        > zero to show if the date is before, equal to or after the specified
        > date. No need to use a regex here
        >[/color]


        Comment

        • Wayne Wengert

          #5
          Re: Regular Expression Question

          Thank you

          "Peter Macej" <peter@vbdocman .com> wrote in message
          news:e5wNxH4QGH A.4740@TK2MSFTN GP14.phx.gbl...[color=blue][color=green]
          >> The problem is in the [- /.] clause. In searching[/color]
          >
          > If I understand, you want to match one of the following characters -, /, .
          > as date delimiters. You need to escape at least the "." because "." is
          > used in regex as "any character". It works with [\- \/\.]
          >
          >
          > --
          > Peter Macej
          > Helixoft - http://www.vbdocman.com
          > VBdocman - Automatic generator of technical documentation for VB, VB .NET
          > and ASP .NET code[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Regular Expression Question

            "Wayne Wengert" <wayneSKIPSPAM@ wengert.org> schrieb:[color=blue]
            >I hope this is an appropriate group for this question - if not, let me know
            >where I should take this question.
            >
            > I want a regular expression that will validate a date in the format
            > mm/dd/yyyy. I actually want to verify that the date is between 1/1/1900
            > and 1/1/1960 but I cannot get past the basic validation of the date.[/color]

            You could use 'Date.Parse'/'Date.ParseExac t' for this purpose. If the date
            can be parsed, you can compare the resulting 'Date' object to the two
            bounds.

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://classicvb.org/petition/>

            Comment

            • Wayne Wengert

              #7
              Re: Regular Expression Question

              Thanks for the response. I am going to try the CompareTo method suggested
              earlier. I'll see if I can make that work.

              Wayne

              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
              news:utFvdc4QGH A.4452@TK2MSFTN GP12.phx.gbl...[color=blue]
              > "Wayne Wengert" <wayneSKIPSPAM@ wengert.org> schrieb:[color=green]
              >>I hope this is an appropriate group for this question - if not, let me
              >>know where I should take this question.
              >>
              >> I want a regular expression that will validate a date in the format
              >> mm/dd/yyyy. I actually want to verify that the date is between 1/1/1900
              >> and 1/1/1960 but I cannot get past the basic validation of the date.[/color]
              >
              > You could use 'Date.Parse'/'Date.ParseExac t' for this purpose. If the
              > date can be parsed, you can compare the resulting 'Date' object to the two
              > bounds.
              >
              > --
              > M S Herfried K. Wagner
              > M V P <URL:http://dotnet.mvps.org/>
              > V B <URL:http://classicvb.org/petition/>[/color]


              Comment

              Working...