开发者

Kohana 3.2 Validation in Birthdate

what i wanted to do is to validate if the age is not under 18 or over 33

public function validate($arr) {
    return Validation::factory($arr)
        ->rule('username', 'not_empty')
        ->rule('last_name', 'not_empty')
        ->rule('first_name', 'not_empty')
        ->rule('email', 'not_empty')
        ->rule('email', 'email_dom开发者_Python百科ain')
        ->rule('phone_num', 'not_empty')
        ->rule('birthdate', 'not_empty')
        ->rule( 'birthdate', array( $this, 'check_birthday' ) );     
}

public function check_birthday()
{
    check if age is not under 18 or over 33
   return boolean;

}


You can use Kohana_Date constants, something like:

return ($date < (time() - 18 * Date::YEAR)) AND ($date > (time() - 33 * Date::YEAR));

or

return Valid::range($date, time() - 33 * Date::YEAR, time() - 18 * Date::YEAR);

Turn the date format into timestamp with strtotime if you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜