Reputation: 232
I have a masked textbox where users keep slipping in invalid dates - and when they get saved to SQL SERVER, there's an error. This is my validation on _lostFocus
If txtDate = "" Then
Exit Function
ElseIf Not IsDate(txtDate) Then
Exit Function
End If
I can put in a date such as 19/8/2000 and it passes. How can I validate it so that it's a valid date?
Found the issue - so this function never converts it to mm/dd/yyyy format - it gets automatically converted to dd/mm/yyyy. How would I convert it?
when i format it to txtDate = Format(txtDate , "mm/dd/yyyy") before I run it trhough the little if statement - the date simply gets converted to 8/19/2000 in that case
Inside the textbox the date basically changes to 8/19/2000 - why is it doing that
Upvotes: 0
Views: 533
Reputation: 8004
Why can't you use If Date.TryParse(txtDate, Date)
Then...? If it succeeds then it's a valid date otherwise it's not. Also 19/8/2000 is a valid date, that's why it passes. If you want to show it in another form or another use ToString
with the format you want... Inside the textbox the date basically changes to 8/19/2000 simply because you are formatting it... Also IsDate(txtDate)
this wont work if it's a TextBox, use IsDate(txtDate.Text)
Upvotes: 1