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. Web Development
  3. ASP.NET
  4. Help with regular expression for reg ex validator

Help with regular expression for reg ex validator

Scheduled Pinned Locked Moved ASP.NET
regexcomsaleshelpquestion
5 Posts 3 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.
  • T Offline
    T Offline
    TimWallace
    wrote on last edited by
    #1

    Let me begin by saying I am not fluent in regex. I need a regex that will validate a date AND time value, not just date and not just time...both. I found a regex written by Bernat Sales at regexlib.com that will validate a date AND time entry, however, it only validates it in European formate (dd/mm/yyyy hh:mm:ss). I need it to validate only in American format (mm/dd/yyyy hh:ss:mm). Can someone, out of the goodness of their heart, please modify this regex to accomplish my goal of validating in American format. Here is Bernat's creation from which you can start: ^((((([0-1]?\d)|(2[0-8]))\/((0?\d)|(1[0-2])))|(29\/((0?[1,3-9])|(1[0-2])))|(30\/((0?[1,3-9])|(1[0-2])))|(31\/((0?[13578])|(1[0-2]))))\/((19\d{2})|([2-9]\d{3}))|(29\/0?2\/(((([2468][048])|([3579][26]))00)|(((19)|([2-9]\d))(([2468]0)|([02468][48])|([13579][26]))))))\s(([01]?\d)|(2[0-3]))(:[0-5]?\d){2}$ Again, I am not a regex guru, nor do I plan to be. I just need this regex for a current page I'm writing. Thanks in advance.

    N W 2 Replies Last reply
    0
    • T TimWallace

      Let me begin by saying I am not fluent in regex. I need a regex that will validate a date AND time value, not just date and not just time...both. I found a regex written by Bernat Sales at regexlib.com that will validate a date AND time entry, however, it only validates it in European formate (dd/mm/yyyy hh:mm:ss). I need it to validate only in American format (mm/dd/yyyy hh:ss:mm). Can someone, out of the goodness of their heart, please modify this regex to accomplish my goal of validating in American format. Here is Bernat's creation from which you can start: ^((((([0-1]?\d)|(2[0-8]))\/((0?\d)|(1[0-2])))|(29\/((0?[1,3-9])|(1[0-2])))|(30\/((0?[1,3-9])|(1[0-2])))|(31\/((0?[13578])|(1[0-2]))))\/((19\d{2})|([2-9]\d{3}))|(29\/0?2\/(((([2468][048])|([3579][26]))00)|(((19)|([2-9]\d))(([2468]0)|([02468][48])|([13579][26]))))))\s(([01]?\d)|(2[0-3]))(:[0-5]?\d){2}$ Again, I am not a regex guru, nor do I plan to be. I just need this regex for a current page I'm writing. Thanks in advance.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You may look at this tool http://www.ultrapico.com/Expresso.htm[^] or search here http://www.regexlib.com/(A(ETSM97iRt59npddwlQbtzFNef5emeob0TT2o8x42-2FZE4R5sd9jQ_I7XKHMO3HGLxVg4cIJnDRXTjAozW-fMhAp1a-s43iaZi06M4wawpE1))/DisplayPatterns.aspx[^]


      I know the language. I've read a book. - _Madmatt

      T 1 Reply Last reply
      0
      • N Not Active

        You may look at this tool http://www.ultrapico.com/Expresso.htm[^] or search here http://www.regexlib.com/(A(ETSM97iRt59npddwlQbtzFNef5emeob0TT2o8x42-2FZE4R5sd9jQ_I7XKHMO3HGLxVg4cIJnDRXTjAozW-fMhAp1a-s43iaZi06M4wawpE1))/DisplayPatterns.aspx[^]


        I know the language. I've read a book. - _Madmatt

        T Offline
        T Offline
        TimWallace
        wrote on last edited by
        #3

        Thanks for the search suggestion, but that is to the site where I found Bernat's regex by searching already. His is the closest I found to what I need (it only needs to swap the month and date tests). When I have time (won't for a month), I'll check out the tool to which you sent me a link.

        1 Reply Last reply
        0
        • T TimWallace

          Let me begin by saying I am not fluent in regex. I need a regex that will validate a date AND time value, not just date and not just time...both. I found a regex written by Bernat Sales at regexlib.com that will validate a date AND time entry, however, it only validates it in European formate (dd/mm/yyyy hh:mm:ss). I need it to validate only in American format (mm/dd/yyyy hh:ss:mm). Can someone, out of the goodness of their heart, please modify this regex to accomplish my goal of validating in American format. Here is Bernat's creation from which you can start: ^((((([0-1]?\d)|(2[0-8]))\/((0?\d)|(1[0-2])))|(29\/((0?[1,3-9])|(1[0-2])))|(30\/((0?[1,3-9])|(1[0-2])))|(31\/((0?[13578])|(1[0-2]))))\/((19\d{2})|([2-9]\d{3}))|(29\/0?2\/(((([2468][048])|([3579][26]))00)|(((19)|([2-9]\d))(([2468]0)|([02468][48])|([13579][26]))))))\s(([01]?\d)|(2[0-3]))(:[0-5]?\d){2}$ Again, I am not a regex guru, nor do I plan to be. I just need this regex for a current page I'm writing. Thanks in advance.

          W Offline
          W Offline
          WaqasYousuf
          wrote on last edited by
          #4

          Here you can use it Will detect American Date and time with whitespace RegExp: /[\d]{2}\s[\d]{2}\s[\d]{4} [\d]{2}:[\d]{2}:[\d]{2}/g

          T 1 Reply Last reply
          0
          • W WaqasYousuf

            Here you can use it Will detect American Date and time with whitespace RegExp: /[\d]{2}\s[\d]{2}\s[\d]{4} [\d]{2}:[\d]{2}:[\d]{2}/g

            T Offline
            T Offline
            TimWallace
            wrote on last edited by
            #5

            Thanks, but that won't validate February or 30 versus 31 days properly.

            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