Jump to content

Validation issue


jkkenzie

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.