![]() |
24hr time validation
Anyone got a simple function that will validate a time input into form (i.e. should be in format 00:00:00)? If not, what's the best way to do this? Cheers.
|
Validating time from a string is hard, there are so many formats it is difficult for you to determine. I suggest making drop down boxes for each field, this gives them no leeway in how to format things. When it comes to input you have the format, the less leeway you give your users the better. You wouldn't think it, but someone will always come around with some weird way they format it that breaks it. Humans can validate information infinitely better than computers, your users likely do not know this.
|
i suppose what i'm getting at is if i wanted the date entered in format 00:00:00 what is the best way to validate that? ereg, preg, explode etc?
|
The simplest way would be to do this (short answer: use explode):
PHP Code:
|
thanks. That was my initial inclination. Think i'll go with that. Wondered if using ereg or preg would be better but dont really know so much about those functions.
|
i.e. how would i validate that the character ':' isnt in the correct places? What would be in the array if $time was 00000000?
|
Quote:
|
Regular expressions would be the best way to do that, use this expression:
[0-9]{2}:[0-9]{2}:[0-9]{2} |
| All times are GMT. The time now is 07:49 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0