lonnieezell / Bonfire

Jumpstart your CodeIgniter web applications with a modular, HMVC-ready, backend.
http://cibonfire.com
1.39k stars 524 forks source link

Validation rule for names, UTF8 compatible #886

Open xcript opened 11 years ago

xcript commented 11 years ago

Please add an UTF8 compatible validation rule for names. This should work:

public function name($str)
{
    return ( ! preg_match("/^\p{L}[\p{L} .-]+$/u", $str)) ? FALSE : TRUE;
}
ragingdave commented 11 years ago

It would probably be better to add this as more of another validation rule checkbox than just an overall check.

xcript commented 11 years ago

It's a function, which can be used as a validation rule. Maybe it could be a new checkbox too.

sourcejedi commented 11 years ago

This seems the wrong place to check UTF8 compatibility! I don't understand the code, so perhaps your definition of UTF8 compatibility is different from mine.

However if the form is submitted with a UTF8 charset, and the form data is not valid UTF8 encoded, that's a software bug. We can't blame the poor user for it! We should give a technical error targeted at troubleshooters, not one written for users. (Why should users know what UTF8 means???).

Maybe you know there are bad browsers that we're not going to work around. Is that it? In that case we still shouldn't complain unintelligibly about UTF8 to our users! We could tell users that certain browsers are broken and they should upgrade their browser. UTF8: it's the law.

xcript commented 11 years ago

I don't know what you are talking about. I'm talking about Bonfire, not any application based on it.

Try to validate the name "Subašić" with the validation rule "alpha" and you will know what I mean.

sourcejedi commented 11 years ago

Apologies @script. I missed the focus on people's names. Having understood the question I respectfully suggest not doing this.

How important is it to deny people with names containing

If there are worries about specific characters in name fields - newlines or various other ASCII control characters, the deprecated unicode formatting characters - it seems better to blacklist the ones we don't want. (I wouldn't object to banning runs of multiple space characters either).

xcript commented 11 years ago

No problem for me, but we have to congretize the context we are talking about. The validation rule should not be used for usernames or any data uncontolled users could enter. My context is a validation of data entered in a controlled environment. The developer is responsible for the use of it!

Thanks for the links. They are very interesting!

In my case I save lists of names of soccer players for a game script. This is a controlled environment, because only a few known users enters the data.

Again: I'm talking about a validation rule developers could use for their application. Any developer should be aware of the risks. You won't give back your driver's license, because you possibly could driving through a red traffic light. This rule is missing in Bonfire. If the Bonfire team decides not to integrate it, then this issue maybe helps some others to get it, if they need it.

mwhitneysdsu commented 11 years ago

It looks like CodeIgniter has a fix in place for alpha() in v3, but it hasn't been back-ported to v2.x (I'm also not 100% sure it works, since it's dependent on using setlocale()). We probably should look at updating alpha_extra() in libraries/MY_Form_validation.php to handle international characters as well.