This topic is locked

validate datetime fields

5/13/2011 5:33:58 PM
PHPRunner Tips and Tricks
G
globiws author

Often we have MySQL datetime fields (YYYY-mm-dd HH:mm:ss) in our forms.

The available "edit as" options are only for date or time.
Although this is not the best validation as it doesn't cater for incorrect dates or leap years, it does ensure a datetime format of:

(1000-3999)-(1-12)-(1-31) (00-24):(00-59):(00-59)
Edit your field as a text field, validate as a regular expression, and set the regexp to:

^([1-3][0-9]{3,3})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][1-9]|3[0-1])\s([0-1][0-9]|2[0-4])<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17026&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />[0-5][0-9])<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17026&image=2&table=forumtopics' class='bbc_emoticon' alt=':(' />[0-5][0-9])$