Reputation:
I have two validation for date and time as below in text boxes:
00/00\ 00:00;0;0;_
It will take (dd/mm hh:mm) and works fine
But sometimes i put
34/34 56:78 it will take , But it shouldn't
Date sholdnot go beyond 31, month 12 time 24 and minute 59
Please help
Upvotes: 1
Views: 3286
Reputation: 23067
I just encountered this problem with a Credit Card expiration date field yesterday. I'd stupidly changed 00/0000 as input mask to 00/00, and encountered the problem you're having. the issue is that if the second pair of digits is a valid date, it will be interpreted as a date and the current year will be supplied tacitly. Thus, if you enter:
06/09
for Jun 2009, it will be stored as:
06/09/2009
On the other hand, if you enter:
06/34
it will be interpreted as
06/01/1934
So far as I can see, the only way for you to do what you want is to use a 4-digit year.
Upvotes: 1
Reputation: 15384
Approach the problem differently. Give the user a calendar to pick from. You could use something like Allen Browne's Popup Calendar
Disable and lock the text field and you can guarantee that the format is correct.
Upvotes: 0
Reputation: 4353
Input masks in Access cannot be restricted to ranges of values, like with a RegExp. Only way to do this is use some validation (which can be done on a keypress if you want to).
Upvotes: 0
Reputation: 125488
validate the date using IsDate()
Public Function ValidateDate(input As String) As Boolean
ValidateDate = IsDate(input)
End Function
this returns a boolean value, True if the input is a valid date string, False if it isn't. The maximum values are
Day: 31
Month: 12
Hour: 23
Min: 59
Sec: 59
Upvotes: 0