Help with validator [SOLVED]

edited July 2012 in News & Announcements
Hello,

I have two validations on a form that give me php errors.

1. $this->validator->add_rule('confirm_password', 'trim|required|xss_clean|matches[password]', 'The passwords do not match', $this->input->post('confirm_password');
I get the error: Message: call_user_func_array() expects parameter 1 to be a valid callback, function 'trim|required|xss_clean|matches[password]' not found or invalid function name

Filename: libraries/Validator.php

I've tried this: $this->validator->add_rule('confirm_password', 'trim|required|xss_clean|is_equal_to', 'The passwords do not match', array($this->input->post('confirm_password'), 'password'));

Doesn't work either.

2. $this->validator->add_rule('password', 'trim|required|xss_clean|alpha_dash', 'Please enter in a valid password', $this->input->post('password'));
I get the error: Message: call_user_func_array() expects parameter 1 to be a valid callback, function 'trim|required|xss_clean|alpha_dash' not found or invalid function name

Can you please help?

Comments

  • edited 11:55AM
    Ok, found the solution:
    $this->validator->add_rule('email', 'valid_email', 'Please enter in a valid email', $this->input->post('email')); $minLength = $this->config->item('password_min_length', 'tank_auth'); $minLengthMsg = "The password should be at least $minLength long."; $this->validator->add_rule('password', 'length_min', $minLengthMsg, array($this->input->post('password'), $minLength)); $maxLength = $this->config->item('password_max_length', 'tank_auth'); $maxLengthMsg = "The password should not be longer than $maxLength long."; $this->validator->add_rule('password', 'length_max', $maxLengthMsg, array($this->input->post('password'), $maxLength)); $this->validator->add_rule('password', 'regex', 'The password can contain only numbers, letters, underscores or dashes', array($this->input->post('password'), '/^([-a-z0-9_-])+$/i')); $this->validator->add_rule('confirm_password', 'required', 'The passwords do not match', array($this->input->post('confirm_password'), 'password'));
  • edited 11:55AM
    Correction for password validation, using this:
    $this->validator->add_rule('password', 'is_safe_character', 'The password can contain only numbers, letters, underscores or dashes', $this->input->post('password'));
    Instead of the regex.
Sign In or Register to comment.