sudsy1970 Posted November 23, 2008 Share Posted November 23, 2008 Hi all, i have a new member register form on my website in which i ask for a dob. i would like to check that a valid date of birth is entered. however the more i look at it the harder it seems to get. i was thinking that i could use the following code. $date = explode("/", "9/2/1983"); $day = $date[0]; $month = $date[1]; $year = $date[2]; to check each part, day should be 0 and 31, month 1 and 12 and say year greater than 1920 but less than 2008. so the first problem i have is the format of the string. i.e the American format of (year/month/day) or British (day/month/year) how can i convert the string in order to check it or ensure that it is a set format ? then what if someone uses 14-09-2007 instead of / does the explode statement still work? then there is the leap year and month issues that i have no clue about. such as if someone puts 29 Feb when not a leap year or 31 June which doesn't exist. Any suggestions or clues? cheers sudsy Link to comment https://forums.phpfreaks.com/topic/133924-solved-stuck-on-date-of-birth-validation/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2008 Share Posted November 23, 2008 Use three dropdown select boxes for the day, month, and year. Then use the php checkdate() function to make sure the date is valid - http://us.php.net/manual/en/function.checkdate.php Link to comment https://forums.phpfreaks.com/topic/133924-solved-stuck-on-date-of-birth-validation/#findComment-697128 Share on other sites More sharing options...
sudsy1970 Posted November 23, 2008 Author Share Posted November 23, 2008 cheers will give that a go. Link to comment https://forums.phpfreaks.com/topic/133924-solved-stuck-on-date-of-birth-validation/#findComment-697176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.