In Codeigniter 3 I use alpha to validate form for only letters
$this->form_validation->set_rules('firstname', 'FirstName', 'trim|required|alpha', array('required' => 'please refill', 'alpha' => 'don't want integer') );
but the problem is the Thai Language letter is not work T_T(it’s work only for English letter). I have already put a meta charset utf-8 on head section, but it’s not work too. How should I do?
Advertisement
Answer
As one of the solution you can use the regex_match rule and specify allowed characters.
Or you can override the alpha
rule and implement it with help of preg_match function. Check the Extending Native Libraries section of the CodeIgniter docs.
Also you can try to play with locales. The alpha
rule is implemented using the ctype_alpha function. According to the docs, by default, it uses the standard C locale([A-Za-z]
). You can try to change locale using the setlocale function.