jkkenzie Posted August 21, 2008 Share Posted August 21, 2008 I would like to validate my date field in this format: yyyy-mm-dd i.e It should be 10 characters, all digits, first four then a "-" folowed by two digits then a "-" and finally the last two digits. The year must be greater than 2001, date (max) should correspond with the month i.e january =31 days, february=28/29 days. In PHP and Javascript. Link to comment https://forums.phpfreaks.com/topic/120698-validation-issue/ Share on other sites More sharing options...
paul2463 Posted August 21, 2008 Share Posted August 21, 2008 you could write a javascript funcion such as this to do it for you function validateDate(var datestring) { var returnvar = false; if(parseDate(datestring)) //check to see if it is a valid date { var brokenDate=datestring.split(”-“); //break the datestring up if (brokenDate[0] > 2001) //check the year is greater than 2001 { //check months and days(max) here, if all good make returnvar = true } } return returnvar; } [/code not done all the coding but given you a start Link to comment https://forums.phpfreaks.com/topic/120698-validation-issue/#findComment-621938 Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2008 Share Posted August 21, 2008 You can validate the format using a preg_match() statement (which will return the separate fields in an array that can be used in the following comparisons.) You can validate the date using a checkdate() statement (checks for valid year/month/day combinations.) You can check the year using a simple conditional statement. Link to comment https://forums.phpfreaks.com/topic/120698-validation-issue/#findComment-621954 Share on other sites More sharing options...
jkkenzie Posted August 21, 2008 Author Share Posted August 21, 2008 Thanks guys , how about PHP server side validation,?? Link to comment https://forums.phpfreaks.com/topic/120698-validation-issue/#findComment-621963 Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2008 Share Posted August 21, 2008 Since you asked this in a php forum, my post above mentioned php methods. Link to comment https://forums.phpfreaks.com/topic/120698-validation-issue/#findComment-621983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.