Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for valdi date 1

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
GB
How do you check if a string is a valid date in VBScript?
 
Take a look at the IsDate() function.
Check this link for an example.

There are limitations of course and it all depends on your date structure and what you expect for input.
If you wanted your date formatted as dd/mm/yyyy but someone entered it as mm/dd/yyyy and the month and day numbers were both 12 or lower then you could tell that a mistake had been made.

I do not know how much tolerance IsDate() has for different separator characters and that is something you may have to take into account. If someone uses hyphens, underscores, spaces or backslashes rather than forward slashes you may have trouble recognizing it as a valid date.
You could use regular expressions to evaluate the value and convert typical incorrect characters into the correct ones then test the result with IsDate().

If you really want to control the date you may be better off using a date picker script or control rather than free type entry.


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top