CodeIgniter Forums
CodeIgniter Form Validation for a Name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: CodeIgniter Form Validation for a Name (/thread-68347.html)



CodeIgniter Form Validation for a Name - june123 - 06-27-2017

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.


RE: CodeIgniter Form Validation for a Name - Narf - 06-27-2017

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.


RE: CodeIgniter Form Validation for a Name - june123 - 06-27-2017

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


RE: CodeIgniter Form Validation for a Name - Martin7483 - 06-27-2017

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


RE: CodeIgniter Form Validation for a Name - Paradinight - 06-27-2017

(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


RE: CodeIgniter Form Validation for a Name - ciadvantage - 06-30-2017

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


RE: CodeIgniter Form Validation for a Name - cartalot - 07-01-2017

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