Another way to validate time format

Views: 11 Last modified: August 03rd, 2011 Comments: 0

This is another way to check the time format instead of this one.

<?php
function check_time_format($time)
{
	$valid = false;
	if (preg_match('/(\d\d):(\d\d):(\d\d)/', $time))
	{
		$valid = true;
	}

	return $valid;
}
?>

Example

<?php
$time = '23:35:58';

function check_time_format($time)
{
	$valid = false;
	if (preg_match('/(\d\d):(\d\d):(\d\d)/', $time))
	{
		$valid = true;
	}

	return $valid;
}

if (check_time_format($time))
{
	echo 'valid';
}
else
{
	echo 'not valid';
}
?>
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {5+6} =  
    Anything to add ?

        You must be logged in to post a comment.