check date validation


Dear Experts,
      
      i am trying to enter valid date in maskedit text box. for that i write following code:
      
      maskedit1.format = "dd-mm-yyyy"
      maskedit1.mask = "##-##-####"

      when i enter date like 12-15-1999 in that maskeditbox, instead of giving error it changes to 15-12-1999 automatically. so how can i prevent user to enter invalid date. means how can i check validity of date. i think you understand my problem...

      so please give some information with code if possible.

TIA,
From Tushar
tushar_kapadiAsked:
Who is Participating?
 
caraf_gConnect With a Mentor Commented:
pietjepuk? :-)

Don't use the date functionality in the masked edit box. It gives you all the lovely <bah> VB functionality, such as interpreting something with 12, 15 and 1999 in it always as 15 December 1999, whether the user used the correct format or not.

Instead, just use the correct ##-##-#### mask, but do the validation yourself.
0
 
pietjepukCommented:
With 12-15-1999 the format is clear because there is no fifteenth month. Basically there is no way of preventing a user typing 01-02-1999 when he/she means 02-01-1999 in a textbox because both are valid dates.

A way of preventing this is to use the calendar control. This control always returns the chosen date in the same format.
0
 
mark2150Commented:
Add a third m to the format statement and then you'll name the month. Use ISDATE to validate.

M

0
 
pietjepukCommented:
I was a bit too quick answering the question before reading it.
0
All Courses

From novice to tech pro — start learning today.