Results 1 to 8 of 8

Thread: Date validation

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    Date validation

    Hi

    Can anyone tell me how to validate a date entry in a text box. I want to ensure that the date is entered as 01/01/05 as opposed to 01.01.05 or 01-01-05. Alternatively can I set it up so that the "/" is placed automatically?

    thanks

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Date validation

    Use a MaskedEdit control instead of textbox. It provides all those features.

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Date validation

    Or use a date picker
    Frans

  4. #4
    New Member
    Join Date
    May 2005
    Location
    Syria
    Posts
    4

    Re: Date validation

    hi

    you can use this code

    VB Code:
    1. Private Sub Text1_LostFocus()
    2. Text1.Text = Format(Text1.Text, "dd/mm/yy")
    3. End Sub
    4.  
    5. ()
    Last edited by fadi_r; May 19th, 2005 at 05:53 AM.

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Date validation

    I think MaskedEdit control would be the best option....
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    Re: Date validation

    Thanks to all who replied. I will try out the various suggestions..please ignore the duplicate post

    Thanks
    Anne

  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Date validation

    Take a look at This Post
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Date validation

    Quote Originally Posted by fadi_r
    hi

    you can use this code

    VB Code:
    1. Private Sub Text1_LostFocus()
    2. Text1.Text = Format(Text1.Text, "dd/mm/yy")
    3. End Sub
    4.  
    5. ()
    Fadi_r,

    Using your code try entering the following value into Text1: 010101
    You will see that the function returns: 27/08/1927

    It returns 27/08/1927 because then this date is 10,101 days greater that 30/12/1899 which I believe is the base date that windows uses to determine the date.

    But if you enter 01/01/01 or 01/0/2001 then it will return 01/01/2001.

    But I agree with the others a Datepicker is the way to go!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width