Validated Given Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Validated Given Date

Post 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
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post 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.!
Post Reply