开发者

validate date - problem php

开发者 https://www.devze.com 2023-03-13 18:28 出处:网络
i am trying this code to validate a date but i get false. what is the reason of that? function validate_age($form) {

i am trying this code to validate a date but i get false. what is the reason of that?

function validate_age($form) {
        $str =开发者_如何学JAVA "1977/03/27";

        $stamp = strtotime( $str );

        if (!is_numeric($stamp)) {
            echo ("nop");
            return FALSE;
        }

        $year  = date( 'Y', $stamp );
        $month = date( 'm', $stamp );
        $day   = date( 'd', $stamp );


        if (checkdate($year, $month, $day)){
            return TRUE;
        }

        return FALSE; //stops here
}

validate_age($form);

thanks


Check the order of your arguments

checkdate($month, $day, $year);

It's all wrote in the php official docu: http://it.php.net/checkdate


month supposed to be from 1 to 12 (no zeros in front)

checkdate($month, $day, $year); as in checkdate(3, 27, 1977); not checkdate(03, 27, 1977); so for month you should use $month = date( 'n', $stamp );

0

精彩评论

暂无评论...
验证码 换一张
取 消