Hey Guys, Can you help me Date validation rule? I have form and user insert date like this format "2010-07-25".
Hey Guys, Can you help me Date validation rule? I have form and user insert date like this format "2010-07-25".
public function isValidDate($attribute,$params)
{
if(!$this->hasErrors()) // we only want to authenticate when no input errors
{
$date = $this->date;
if(!checkdate(date("m",strtotime($date)),date("d",strtotime($date)),date("Y",strtotime($date))))
{
$this->addError('date','Invalid date.');
}
}
}
please see http://www.yiiframework.com/doc/api/CTypeValidator
e.g.
array('NAME_OF_FIELD_TO_VALIDATE', 'type', 'type'=>'datetime', 'datetimeFormat'=>'dd-MM-yyyy hh:mm'),
Sorry nemo, I misunderstood your question; Sniper is right.