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 Quote Link to comment Share on other sites More sharing options...
revraz Posted April 22, 2009 Share Posted April 22, 2009 Check the RegEx forums for examples. Quote Link to comment 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. Quote Link to comment 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 } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.