Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regular Expression for hour

Regular Expression for hour

Scheduled Pinned Locked Moved C#
regexquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BECK7
    wrote on last edited by
    #1

    Hi, i need regular expression to validate the hour, what i need is a format like this: 08:00:00 (hours, minutes and seconds). Im using this formatting but its not working, any ideas?? strFormat = @"^\d{2}\:\d{2}\:\d{2}\$"; thanks in advance...

    A M O 3 Replies Last reply
    0
    • B BECK7

      Hi, i need regular expression to validate the hour, what i need is a format like this: 08:00:00 (hours, minutes and seconds). Im using this formatting but its not working, any ideas?? strFormat = @"^\d{2}\:\d{2}\:\d{2}\$"; thanks in advance...

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      You have escaped your "end of string" marker. Take out the "\" before the $ and it should match.

      1 Reply Last reply
      0
      • B BECK7

        Hi, i need regular expression to validate the hour, what i need is a format like this: 08:00:00 (hours, minutes and seconds). Im using this formatting but its not working, any ideas?? strFormat = @"^\d{2}\:\d{2}\:\d{2}\$"; thanks in advance...

        M Offline
        M Offline
        Mohamad Al Husseiny
        wrote on last edited by
        #3

        one another thing this pattern will match somthing like 80:90:95 because you din't specify the range for valid hour,minuts,seconds MCAD

        B 1 Reply Last reply
        0
        • M Mohamad Al Husseiny

          one another thing this pattern will match somthing like 80:90:95 because you din't specify the range for valid hour,minuts,seconds MCAD

          B Offline
          B Offline
          BECK7
          wrote on last edited by
          #4

          Thats true, how can i define the range then? thanks in advance....

          L 1 Reply Last reply
          0
          • B BECK7

            Hi, i need regular expression to validate the hour, what i need is a format like this: 08:00:00 (hours, minutes and seconds). Im using this formatting but its not working, any ideas?? strFormat = @"^\d{2}\:\d{2}\:\d{2}\$"; thanks in advance...

            O Offline
            O Offline
            OmegaMan
            wrote on last edited by
            #5

            Here you go ^(?[0-1]\d|[2][0-3])(?::)(?[0-5]\d)(?::)(?[0-5]\d) Puts it into nice groups of Hour Minutes and Seconds. If it doesn't match it is not valid. It is based on a 24 hour clock. 23:59:59 valid but 24:00:00 is not

            1 Reply Last reply
            0
            • B BECK7

              Thats true, how can i define the range then? thanks in advance....

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              \d{2}:[0-5]\d:[0-5]\d That should do the trick. Max time will be then 99:59:59

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups