Form validation and non-english characters? |
[eluser]axed[/eluser]
Hi, I'm using the Form validation class to check an input field. The rule for the field is required|alpha and it works without any problems when I'm typing in english. But when I'm trying to input some Swedish characters (å ä and ö) the validation fails with the message: The ... field may only contain alphabetical characters. What can i do to solve this? I mean the 'å', 'ä', and 'ö' -signs are all alphabetical characters in Sweden. I'm using UTF-8...
[eluser]danmontgomery[/eluser]
[quote author="axed" date="1264733632"]Hi, I'm using the Form validation class to check an input field. The rule for the field is required|alpha and it works without any problems when I'm typing in english. But when I'm trying to input some Swedish characters (å ä and ö) the validation fails with the message: The ... field may only contain alphabetical characters. What can i do to solve this? I mean the 'å', 'ä', and 'ö' -signs are all alphabetical characters in Sweden. I'm using UTF-8...[/quote] Alpha is considered only a-z and A-Z... If you want anything else you'd have to use a callback function. http://ellislab.com/codeigniter/user-gui...#callbacks
[eluser]jmadsen[/eluser]
I haven't tried this, but wonder if this is correct? The basic form validation rules are in library Validation (edit: actually, Form_validation now. Whichever you are using.), so if you need to use an expanded alphabet on a regular basis, try extending this class and making a "swed_alpha" rule that would include your special characters. I guess that's no different than calling a helper function. Anyone explain advantage/disadvantage of one over the other?
[eluser]tomcode[/eluser]
Right now I work like that : file librairies/MY_Form_validation.php encoded in UTF-8 Code: /** language files fom_validation_lang.php Code: // MY_Form_validation Another possibility I once coded, if I remember right, was using mb_string and set_locale.
|
Welcome Guest, Not a member yet? Register Sign In |