CodeIgniter Form Validation for a Name |
Hello,
When a form takes a person's name as input, it is usually two or three strings separated by spaces i,e. Henry David Lee. However going through CodeIgniter validation rules I couldn't find any rule which supports this. I could find alpha and alpha_dash which wont validate a name. Maybe something like alpha_space is needed so that we dont need to create callback functions for it. Please correct me if I have missed something.
You're missing single quotes, non-English alphabets and perhaps assuming some length limitations which don't really exist.
Also, a lot of countries allow you to legally change your name to "june123", literally.
Yeah, I totally agree.
But having alpha_space would have helped. Also for june123 we already have alpha_numeric, for "june123 Narf" we can use alpha_numeric_spaces
When it comes to names, just have the field be required.
What happens if someones name has a dash in it? Then you would need a alpha_dash_spaces rule
it is easy to create a callback function that is acting as filter for alpha dash spaces. You can use this pattern /^[a-zA-Z\s]+$/ to compare with name and raise errors
if doesnt match in pattern
If you are parsing a lot of names its useful to look at some libraries for ideas. I've used this one:
https://github.com/joshfraser/PHP-Name-Parser |
Welcome Guest, Not a member yet? Register Sign In |