Yii 1.1: age-validator

Validates min/max age by birthdate
10 followers

Installation

  1. Place EAgeValidator.php to <your_app>/protected/extensions/validators/age/ or any convenient directory
  2. Add path alias of extension to import section if you dont want to use full paths to EAgeValidator in your models.

Usage

#method of your model class, that you need to validate
public function rules()
{
    return array(
 
        # If you imported ext.validators.age.EAgeValidator or placed EAgeValidator.php
        # to directory, that is imported (for example, protected/components)
        array('your_birthdate_field_name1', 'EAgeValidator'),
        ...
        # With options and full path to extension   
        array('your_birthdate_field_name2', 'ext.validators.age.EAgeValidator',                    
                  'minAge'=>16, 
                  'maxAge'=>120, 
                  'allowEmpty'=>false
        ),
        ...
    );
}

License

BSD

Contacts

Total 2 comments

#9484 report it
florin p at 2012/08/15 12:21pm
Client Validation

Hi,

How can I integrate with client validation?

#6084 report it
dbk138 at 2011/12/10 07:12pm
Integration with Yii User

Hello,

I am trying to add this to the Yii User module and I am having trouble making it work. I have tried adding it in the validators field on the profile field management and I have also tried adding it to the RegistrationForm model but neither way is working. Has anyone successfully added this to the Yii User module?

Leave a comment

Please to leave your comment.

Create extension