Solved

date validations in dd/mmm/yy format

Posted on 2004-03-28
12
1,315 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
0
Comment
Question by:kedarpd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 10701528
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
0
 
LVL 2

Expert Comment

by:lttia1
ID: 10701535
hi,

How about making a switch to DateTimePicker control. You can custom the control to dd/mmm/yy format.
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 10701537
best would be to use a masked edit box it takes care of this validation by the format
Bhagyesh Trivedi
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kedarpd
ID: 10701654
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
0
 
LVL 2

Expert Comment

by:lttia1
ID: 10701682
You are using which version of vb?
0
 

Author Comment

by:kedarpd
ID: 10701730
Hi lttia1,

i am using Visual Basic 6.0 (sp5) on win 2k platform
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 10701737
Try the function I posted at first. ;)

-FA
0
 
LVL 2

Expert Comment

by:lttia1
ID: 10701749
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.
0
 

Author Comment

by:kedarpd
ID: 10701767
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
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 10701792
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
0
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 250 total points
ID: 10701840

' Returns True if inpDate as string representation of date like
' 16/jan/04 is a valid date. Only workd with dd/mmm/yy format.
Public Function DateIsValid(inpDate As String) As Boolean
    On Error GoTo Err_Handling_DateIsValid

    Dim testVar As Date
    inpDate = Left(inpDate, Len(inpDate) - 2) & "20" & Right(inpDate, 2)
    DateIsValid = True
    testVar = CDate(inpDate)

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


-FA
0
 

Author Comment

by:kedarpd
ID: 10701847
Hi FarzadA


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

Kedar
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Is doing tutor.com teaching in my situation advisable? 2 160
sp_configure 'external scripts enabled', 1; 7 157
printf performancy 11 103
IDE for Python 5 105
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question