Date validation with Zend

Asked

Viewed 189 times

1

How to validate a date using Zend? When the user registers, I need to validate the birthday and see if it is older than 18 years.

I receive 3 fields - day, month and year and would like to validate the registration only for over 18

I found this code, but I do not know how to inform the parameter +18

$validator = new Zend_Validate_Date(array(
    'format' => 'dd-mm-yyyy',
    'locale' => $yourLocale
);

thank you

1 answer

2


Dude, when the person reports the birthday date you can pick up check if the date they reported is earlier than the date to be 18.

For example: If the guy said he was born in 1998-07-07, that date later than the minimum to be 18 years old (which would be in the year 1996). To make these checks whether it is before or after date you can use the methods below:

$dateOne = new Zend_Date(time());
$dateTwo = new Zend_Date(time());

 // verifica se a segunda data é posteRior a segunda 
if ($dateOne->isLater($dateTwo)) {
 // BLABLA
}
  // verifica se a primeira data é antes da segunda
if ($dateOne->isEarlier($dateTwo)) {
 // BLABLA
}
  • isLater and isEarlier are available in zend 2.2?

  • Yes, here’s the place to download the stable version of it: http://framework.zend.com/blog/zend-framework-2-2-0-stable-released.html Mark the answer as useful by clicking the up arrow if you can! Thank you! ^^

  • in the version I have not found, isLater and isEarlier... I will download what recommended and look for them. I have given as resolved, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.