Reputation: 12012
User Entering the Time Value in the Masked Textbox
For Example
User Enter Time like 08:00 (HH:MM)
User Enter Time like 28:00 (HH:MM) , Textbox should not accept this value. Because it should accept from 00 to 23 (HH) and 00 to 59 (MM).
How to do this.
Upvotes: 0
Views: 2274
Reputation: 27342
Have a look at the Validate Event - you can test the value in this event and correct it or error appropriately (depending on what user experience you would like)
Private Sub txtDate_Validate(Cancel As Boolean)
If Not IsDate(txtdate.Text) Then
'fix it here OR
Cancel = True 'don't allow the input
End If
End Sub
Upvotes: 1
Reputation: 30408
Why not use the DateTimePicker instead of the MaskedTextBox? DateTimePicker was specifically designed for allowing the user to enter time values. Set the CustomFormat
to "HH:MM"
Upvotes: 1
Reputation: 24313
I don't know how to get the masked textbox to range check the values as it can't be checked using a format string. You can however use the IsDate() and/or CDate() functions to check and convert to a valid date/time.
?isdate("08:00")
True
?cdate("08:00")
08:00:00
?isdate("28:00")
False
Upvotes: 0