Form validation of CodeIgniter does not allow accents and other "br" characters

2

I'm using the alpha_numeric_spaces rule to validate letters and numbers with space, but when I use any special characters or letters like "ç", validation does not pass, is there any way around this or only by creating a special rule?

Ex:

 $validator->set_rules('nome', 'Nome', 'min_length[3]|max_length[60]|alpha_numeric_spaces');
    
asked by anonymous 20.07.2017 / 22:37

1 answer

2

You need to create your own rule. Here's how CodeIgniter alpha_numeric_spaces implementation is:

public function alpha_numeric_spaces($str) {
    return (bool) preg_match('/^[A-Z0-9 ]+$/i', $str);
}

That is, insensitively ( /i ) will validate strings that contain only 1 or more ( +$ ) letters A through Z, numbers 0 through 9, or spaces. And you will need \p{L} in the validation regex of your input, to pass any accented character of the Latin alphabet, including ç :

$validator->set_rules('nome', 'Nome', array('trim', 'regex_match[/[\p{L}0-9 ]+$/i]'));

Otherwise you can just add ç within the rule: [A-Z0-9Ç ] .

    
21.07.2017 / 14:23