Cake PHP age validation


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.