We help IT Professionals succeed at work.

date validations in dd/mmm/yy format

kedarpd
kedarpd asked
on
Medium Priority
1,357 Views
Last Modified: 2012-08-13
Hi,

I want to validate the date entered in a text box to be in the form of dd/mmm/yy for example the date entered should be 16/jan/04. i want to validate this text in the text box. Any ideas.....

Any suggesstions will be appreciated

regards,
-Kedar
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Hi,
if you are programming Visual Basic you can use the following function:


' Returns True if inpDate as string representation of date like
' 16/jan/2004 is a valid date.
Public Function DateIsValid(inpDate As String) As Boolean
    On Error GoTo Err_Handling_DateIsValid

    Dim testVar As Date
   
    DateIsValid = True
    testVar = CDate(inpDate)

    Exit Function
Err_Handling_DateIsValid:
    If Err.Number = 13 Then
        DateIsValid = False
    End If
End Function


-FA

Commented:
hi,

How about making a switch to DateTimePicker control. You can custom the control to dd/mmm/yy format.
best would be to use a masked edit box it takes care of this validation by the format
Bhagyesh Trivedi

Author

Commented:
Hi Bhagyesh Trivedi,

Thnx for ur suggestions...

Masked edit box takes care only of the format but does not validate the entry. For example if i give the mask as ##/???/## It does take care of te format but if i enter 99/kkk/88 , then it only validates the format and not the text. i want to also validate the text as month cannot be kkk or date cannot be  99 etc.

any ideas ......


Regards

Kedar

Commented:
You are using which version of vb?

Author

Commented:
Hi lttia1,

i am using Visual Basic 6.0 (sp5) on win 2k platform
CERTIFIED EXPERT

Commented:
Try the function I posted at first. ;)

-FA

Commented:
In that case, why don't you consider using DateTimePicker control. You can custom the control to dd/mmm/yy format and no validation has to be done.
It appears in the form of combo box but when you drop down. it is actually a calendar.

Author

Commented:
Hi  FarzadA,

Ur function is good but it doesn't validate for the date part. for exapmle if i give 44/jan/02 it returns true.

Kedar
CERTIFIED EXPERT

Commented:
Because 44/jan/02 means 2-Jan-1944. If you use 44/jan/2002 it returns false.
Is year is right most digits? Or input date is ##/###/## format? I can modify this function.

-FA
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi FarzadA


input date is of format 12/jan/02.
ie ##/???/## wher #-represents numbers
?- represents characters

Kedar
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.