Running functions on form data before/during validation

Ok, so for example if someone is entering a username and I want to make it lowercase before OR at the beginning of validation how can I do this?

I know you can do something similar with trim such as:


[['company_name', 'first_name', 'last_name', 'email', 'username', 'password', 'password2'], 'trim'],

But I assume this doesn’t support any function?

So, I would want to run the strtolower function on the username, what would be the way to go about doing this? Would I need to use the beforeValidate method or can I do something like this?




['username', 'makeLower']


public function makeLower($attribute, $params) {		

	$this->$attribute = strtolower($this->$attribute);

}



I ended up using a FilterValidator.


['username', 'filter', 'filter' => 'strtolower']