Page 1 of 1

Validated Given Date

Posted: Sat Jan 29, 2005 2:58 pm
by jwalsh
Hi,

I'm asking for a date in a text box, and requesting they use the following format mm-dd-yyyy. In my form validation routine, I need to check that this is indeed the format entered, and that the date is an actual valid date.

I'm assuming the format check needs to be done with reg expressions, but I'm not sure exactly how to do this.

Also, the date check should be easy to do with checkdate.

Can someone help with the reg expression?

Thanks Much,

Josh

Posted: Sat Jan 29, 2005 4:32 pm
by neophyte

Code: Select all

if (preg_match("#ї0-9]{2}-ї0-9]{2}-ї0-9]{4}#", $string, $matches))
{
echo "IT'S A MATCH!"

}
Well that should get you matces of 00-00-0000.....

Let me know if it works for you.

Posted: Sat Jan 29, 2005 4:46 pm
by jwalsh
This works great...

Code: Select all

if (preg_match("#ї0-9]{2}-ї0-9]{2}-ї0-9]{4}#", $subs, $matches) == 0) 
	{ 
	$errorst .= "Invalid Date Format, <br>";
	&#125;
Thanks a lot.!