嗨我目前坚持使用php验证,我试图让日期测试对抗 日期();日期以确保日期是最新的,并且不允许任何日期小于当前日期()
public function checkDateField($month, $day, $year)
{
if (!is_numeric($month) || !is_numeric($day) || !is_numeric($year) || !checkdate($month, $day, $year)) {
$msg = '*Invalid date';
// then some where here test the value
of $month $day $year >= date...
something like that?
///
}
return $msg;
}
答案 0 :(得分:0)
也许使用datetime diff函数将你的日期与now()进行比较:http://www.php.net/manual/en/datetime.diff.php
希望这有帮助!
答案 1 :(得分:0)
这样的事情应该有用(假设日期格式为 YYYY-MM-DD
):
function isValidFutureDate($date)
{
if (false === strtotime($date))
{
return false;
}
list($year, $month, $day) = explode('-', $date);
if (false === checkdate($month, $day, $year))
{
return false
}
$now = new DateTime();
$compare = new DateTime($date);
if ($compare < $now)
{
return false;
}
}
答案 2 :(得分:0)
public function checkDateField($month, $day, $year){
if (!is_numeric($month) || !is_numeric($day) || !is_numeric($year) return 'Invalid date';
if (strtotime($year.'-'.$month.'-'.$day.' 23:59:59') < time()){
return 'Invalid time';
}
}