Results 1 to 6 of 6

Thread: Date validation

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878

    Date validation

    I have a text box, into which the user has the opportunity of entering a date.

    What is the best code to use to:
    a) validate to ensure the date is correct
    b) translate whatever they have entered into a standard format date.

    a) should reject 13/13/2002 etc.
    b) should sort out the problems of either 13/12/2002 or 12/13/2002 is valid, but not both.

  2. #2
    Member
    Join Date
    Nov 2001
    Location
    Lincoln,England
    Posts
    60
    Trying using isdate(text1.text) and converting the string to a date data type cdate(text1.text) assumimg isdate returned true.

  3. #3
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    you could opt to use the MaskedEdit control (microsoft), you can specifiy an input mask for the user. It's good.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    THANKS.

    IsDate is true for both 13/6/02 and 6/13/02
    And the CDate always translates it to 13/06/2002

  5. #5
    Member
    Join Date
    Nov 2001
    Location
    Lincoln,England
    Posts
    60
    this depends on the localised settings on the PC, you could use in combination with the format function.

  6. #6
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking My dog ate my harddrive...You don't believe me? Well...*SLAP*

    Why not just use a date picker control? They ship with VB. They can be found under Windows Common Controls 6.Blah...

    If you enter a date into a textbox it can be in the form of:

    Day/Month/Year
    or
    Month/Day/Year
    or
    Day/Year/Month
    or
    Year/Day/Month
    or
    Year/Month/Day
    or
    Month/Year/Day



    Oh, and it all depends on what your system date format is set to. Goto Regional Settings in your control panel to find out.

    Using a datePicker control automatically removes any errors you may get by using dates and having them formatted wrongly...Loads easier.

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