CodeIgniter Forums
Form Validation - problem with some chars - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form Validation - problem with some chars (/showthread.php?tid=51892)



Form Validation - problem with some chars - El Forum - 05-22-2012

[eluser]Unknown[/eluser]
Hi everyone!

I have a problem with some polish chars.

Model fragment:
Code:
...
$name = strtolower($this->input->post('name'));
$surname = strtolower($this->input->post('surname'));
..

Controller fragment:
Code:
$this->form_validation->set_rules('name', '"Imię"', 'trim|required|min_length[3]|alpha');
$this->form_validation->set_rules('surname', '"Nazwisko"', 'trim|required|min_length[3]|alpha');

View fragment:
Code:
echo form_label('Imię', 'name');
echo form_input('name').form_error('name');
    
echo form_label('Nazwisko', 'surname');
echo form_input('surname').form_error('surname');

I set a rule only aplha chars, so then I type character like ł, ą, ę it doesn't pass the validation.

Of course in my database I have set 'ut8_general_ci' and in config database file.


Form Validation - problem with some chars - El Forum - 05-22-2012

[eluser]SPeed_FANat1c[/eluser]
You probably will have to extend form validation class, alpha rule, now it is:\

Code:
function alpha($str)
{
  return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
}

So thats why it is not valid I think.

Or create your custom validation rule.


Form Validation - problem with some chars - El Forum - 05-23-2012

[eluser]Unknown[/eluser]
[quote author="SPeed_FANat1c" date="1337687398"]You probably will have to extend form validation class, alpha rule, now it is:\

Code:
function alpha($str)
{
  return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
}

So thats why it is not valid I think.

Or create your custom validation rule.[/quote]

Thanks. Smile I created my own rule.