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. Regular Expression

Regular Expression

Scheduled Pinned Locked Moved ASP.NET
regextutorial
6 Posts 4 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.
  • J Offline
    J Offline
    jashimu
    wrote on last edited by
    #1

    Hi All, I am wondering how to validate date using regular expression and not allowing any future date if the user wants to put it in anyway. thanks,

    S K B 3 Replies Last reply
    0
    • J jashimu

      Hi All, I am wondering how to validate date using regular expression and not allowing any future date if the user wants to put it in anyway. thanks,

      S Offline
      S Offline
      Shahriar Iqbal Chowdhury Galib
      wrote on last edited by
      #2

      Hi, no, it's not possible with regular expression, regular expression can only validate patterns, you can use compare validator for this purpose or use .NET function DateTime.Now to acquire todays date, then compare it programmatically with the date from user's input. Regular expression for date is (?x)(?:0[1-9]|1[0-2])(/?)(?:0[1-9]|[12][0-9]|3[01])(\1)\d{4}\d/\d/\d{4}

      J 2 Replies Last reply
      0
      • J jashimu

        Hi All, I am wondering how to validate date using regular expression and not allowing any future date if the user wants to put it in anyway. thanks,

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #3

        Just to add to Shahriar Iqbal Chowdhury's answer, you can use the regex validator to do an "idiot check" Client side and use dateTime.TryParse[^] to check server side. There are several attempts to do it here[^] without the regex using JavaScript instead. For the regex pattern, I've always found http://regexlib.com[^] useful, it also gives a summary of how well well the regex matches etc.

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]
        -Or-
        A Dead ringer for Kate Winslett[^]

        1 Reply Last reply
        0
        • S Shahriar Iqbal Chowdhury Galib

          Hi, no, it's not possible with regular expression, regular expression can only validate patterns, you can use compare validator for this purpose or use .NET function DateTime.Now to acquire todays date, then compare it programmatically with the date from user's input. Regular expression for date is (?x)(?:0[1-9]|1[0-2])(/?)(?:0[1-9]|[12][0-9]|3[01])(\1)\d{4}\d/\d/\d{4}

          J Offline
          J Offline
          jashimu
          wrote on last edited by
          #4

          Thank you Iqbal bhi, I will get the user input and then compare with present date in the back end. thanks for the date format.

          1 Reply Last reply
          0
          • S Shahriar Iqbal Chowdhury Galib

            Hi, no, it's not possible with regular expression, regular expression can only validate patterns, you can use compare validator for this purpose or use .NET function DateTime.Now to acquire todays date, then compare it programmatically with the date from user's input. Regular expression for date is (?x)(?:0[1-9]|1[0-2])(/?)(?:0[1-9]|[12][0-9]|3[01])(\1)\d{4}\d/\d/\d{4}

            J Offline
            J Offline
            jashimu
            wrote on last edited by
            #5

            thanks for your reply, I know it can be done using back end Csharp code. But how do I display message to user that something is wrong.

            1 Reply Last reply
            0
            • J jashimu

              Hi All, I am wondering how to validate date using regular expression and not allowing any future date if the user wants to put it in anyway. thanks,

              B Offline
              B Offline
              berba
              wrote on last edited by
              #6

              hi check this please http://p2p.wrox.com/asp-net-1-1/5952-date-regular-expression.html[^] Try to see if you can use compare validator to check the future date..

              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