Posted By

slav123 on 03/23/11


Tagged

cakephpagevalidation


Versions (?)

Cake PHP age validation


 / Published in: PHP
 

URL: http://bin.cakephp.org/view/1184217660

  1. /**
  2. * Poor man's age limit validation
  3. * Due to the lack of simple and exact PHP time diff function,
  4. * we conveniently forget leap years
  5. */
  6. function ageLimit( $data, $reqAge ) {
  7. $date = strtotime( $data['birthday'] );
  8. if( $date !== false && $date !== -1 ) { // strtotime returns -1 < PHP 5.1.0
  9. $diff = time() - $date;
  10. return ( $diff / 31556926 > $reqAge ); // 31556926 seconds in a year
  11. }
  12. return false; // date malformed
  13. }

Report this snippet  

You need to login to post a comment.