Welcome Guest, Not a member yet? Register   Sign In
why is form validation having issue with spaces?
#3

[eluser]Unknown[/eluser]
This problem still exists in CI 2.0.3 but you can use a custom RegEx to validate your names:


Code:
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|callback_validate_name');

function validate_name($str) {
        if (preg_match("/^[A-Z][a-zA-Z -]+$/", $str) !== 0) {
            return true;
        } else {
            $this->form_validation->set_message("validate_name", '%s is not valid.');
            return false;
        }
}

This RegEx expression will ensure that first_name contains letters, dashes and spaces only, must start with upper case letter and must not start with a dash. (source: PHP validation and verification)

Hope this helps.


Messages In This Thread
why is form validation having issue with spaces? - by El Forum - 06-02-2011, 10:56 AM
why is form validation having issue with spaces? - by El Forum - 06-05-2011, 06:18 PM
why is form validation having issue with spaces? - by El Forum - 01-22-2012, 01:41 PM
why is form validation having issue with spaces? - by El Forum - 01-22-2012, 03:06 PM
why is form validation having issue with spaces? - by El Forum - 02-11-2012, 11:31 AM
why is form validation having issue with spaces? - by El Forum - 02-11-2012, 12:52 PM
why is form validation having issue with spaces? - by El Forum - 02-11-2012, 12:57 PM
why is form validation having issue with spaces? - by El Forum - 02-11-2012, 01:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB