Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Form Validation for a Name
#1

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.
Reply
#2

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.
Reply
#3

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  Wink
Reply
#4

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
Reply
#5

(06-27-2017, 07:49 AM)Martin7483 Wrote: 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

André or René a valid names Smile
Reply
#6

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
Reply
#7

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB