public function registration()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('user_name', 'User Name', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('email_address', 'Your Email', 'trim|required|valid_email');`enter code here`
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
}
i have done this in codeigniter performing validation. how can i do similar work in php native ? i mean validation
The way I’ve done it in the past is to build objects for it… a form object, a form field object and a form field validator object.
So you’d create all your field objects and, if required, attach validators to them, then attach the whole lot to the form – so you sort of end up with something like:
The validators deal with things like determining if the field data is required, if the data matches an empty string (RegExp) then it’s not required for instance.
But they can also deal with email validation (with or without getmxrr() lookup) or anything else, you just build Validator types for specific cases… or you have generic Validators:
This gives you as much flexibility as you need with validation. All the
Form::isValid()method does is loops through all the attached fields, checks to see if they have Validators and if so whether theValidator::isValid()method returns true.You could also attach multiple Validators to Fields with something like:
… that’s how I’ve done it anyway.