Add this to your model validation (assuming the field you are checking is 
called 'dob'):


'dob' => array(
        'inRange' => array(
                'rule' => 'isAgeInAcceptedRange',
                'message' => 'You must be between the ages of 18 and 80.'
        )
),


Then add this function to your model:
                        
function isAgeInAcceptedRange($check) {

        list($Y,$m,$d) = explode("-", $check['dob']);

        $userAge = ( date("md") < $m.$d ? date("Y")-$Y-1 : date("Y")-$Y );
                
        if ( ($userAge >= 18) && ($userAge <= 80) ):
                return true;
        else:
                return false;
        endif;

}


Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 22 Jun 2010, at 10:16, jerry wrote:

> I have been using cakephp for a few weeks now but i have failed to
> know how to validate a date for example a birthday to make sure it's
> now greater than the current date.Could anyone point me to the right
> direction
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to