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. date validity

date validity

Scheduled Pinned Locked Moved C#
question
3 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.
  • F Offline
    F Offline
    fmardani
    wrote on last edited by
    #1

    In a textbox a date is entered. How can you check if this is a valid date or infact a date at all? Thanks

    T P 2 Replies Last reply
    0
    • F fmardani

      In a textbox a date is entered. How can you check if this is a valid date or infact a date at all? Thanks

      T Offline
      T Offline
      tatchung
      wrote on last edited by
      #2

      i believe u can do this with regex though im cluless what its coresponding regex term is. try to google it:-O Aim small, miss small...

      1 Reply Last reply
      0
      • F fmardani

        In a textbox a date is entered. How can you check if this is a valid date or infact a date at all? Thanks

        P Offline
        P Offline
        Polis Pilavas
        wrote on last edited by
        #3

        You can do that quite easily by writing your code inside a try/catch block like below:

        try
        {
        DateTime tmp = DateTime.Parse(this.textBox1.Text);
        }
        catch (Exception exc)
        {
        MessageBox.Show("This is not a valid date\n\nError Message: " + exc.Message);
        return;
        }
        MessageBox.Show("Date is valid");

        Regards, Polis Can you practice what you teach?

        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