Woodburn2006 Posted April 22, 2009 Share Posted April 22, 2009 im new to verification in php so i was wondering how you would vaerify that a date intered in a form is in the form of 'YYY-MM-DD' ? thanks Link to comment https://forums.phpfreaks.com/topic/155212-verifying-dates/ Share on other sites More sharing options...
revraz Posted April 22, 2009 Share Posted April 22, 2009 Check the RegEx forums for examples. Link to comment https://forums.phpfreaks.com/topic/155212-verifying-dates/#findComment-816516 Share on other sites More sharing options...
premiso Posted April 22, 2009 Share Posted April 22, 2009 preg_match is one way. Javascript would be another, granted JS could be disabled. Link to comment https://forums.phpfreaks.com/topic/155212-verifying-dates/#findComment-816517 Share on other sites More sharing options...
JonnoTheDev Posted April 22, 2009 Share Posted April 22, 2009 if (preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $date)) { // matched } else { // no match } Link to comment https://forums.phpfreaks.com/topic/155212-verifying-dates/#findComment-816520 Share on other sites More sharing options...
Daniel0 Posted April 22, 2009 Share Posted April 22, 2009 $date = '2009-04-22'; $parts = explode('-', $date); if (count($parts) != 3 || !checkdate($parts[1], $parts[2], $parts[0])) { echo 'Invalid'; } else { echo 'Valid'; } Better than regex because it checks that it's actually a real date. Link to comment https://forums.phpfreaks.com/topic/155212-verifying-dates/#findComment-816861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.