Hi Richard,
thanks for the help.
So one question do you execute this code as a part of the Validation and
prompt an error message or it just check for the right error format...
Here yer go ... as recommended by Cowboy, and cut'n'paste directly from an
app I'm writing.
The first test is for an ordinary date, explicitly coded to en-GB 'cos
browsers don't appear to return the right nationality and this is for UK.
The second test is because the users are occasionally lazy about 4 digit
years, the third test allows for year only entry - a requirement of the app
I'm writing, and the fourth test is just getting fancy; nobody will ever
type the word "today" into a text box. To parse other date formats simply
add more tests.
Cheers
Richard
_____________________________________________
Dr. Richard Petheram
AdlZ Ltd.
E-mail: richard_at_adlz.co.uk
_____________Web:
www.adlz.co.uk ____________
[ CODE FOLLOWS ]
Public Shared Function ParseDate(ByVal pString As String, Optional ByRef
IsValid As Boolean = True) As DateTime
Dim lDTF As DateTimeFormatInfo =
CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat
Dim lResult As DateTime
Try
lResult = DateTime.Parse(pString, lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
Try
lResult = DateTime.ParseExact(pString, "dd/MM/yy", lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
Try
lResult = DateTime.ParseExact(pString, "yyyy", lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
If pString.Trim.ToLower = "today" Then
lResult = DateTime.Today.Date
IsValid = True
Return lResult
End If
IsValid = False
Return Nothing
End Function
[ END OF CODE ]