如何“验证” CakePHP中的人名? [英] How to "Validate" Human Names in CakePHP?

查看:392
本文介绍了如何“验证” CakePHP中的人名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,它应该检查有效的人名,但最近破解了一个名称的空格,所以我们添加了空格到验证器。

而不是这样做,有没有办法添加一个黑名单到CakePHP的验证器来阻止所有无效字符,而不是允许有效的字符?

I have a PHP script that is supposed to check for "valid" human names, but recently cracked against a name with a space, so we added spaces to our validator.
Rather than doing this, is there a way to add a blacklist to CakePHP's validator to block all "invalid" characters, rather than allowing "valid" ones?

注意:我知道如何在PHP(通常)这样做,但使用CakePHP的验证语法是不同的。

NOTE: I know how to do this in PHP (generally) but using CakePHP's validator syntax is different.

推荐答案

我同意其他意见,验证一个名字可能是一个坏主意。

I agree with the other comments that validating a name is probably a bad idea.

几乎所有你能想到的验证,将有一个名字破坏你的规则的人。如果你对这样的想法感到满意,你会阻止真正的人输入他们的名字,那么你可以尽可能多地验证它。但是,您放入的验证规则越多,您就越有可能找到一个无法登录的真实用户。

For virtually everything you can think of to validate, there will be someone with a name that breaks your rule. If you're happy with the idea that you're going to be blocking real people from entering their names, then you can validate it as much as you like. But the more validation rules you put in, the more likely you are to find a real person who can't sign in.

这里有一个指向某个页面的链接人们试图验证的显而易见的(而不是那么明显的)事情,它们可以跳过它们:

Here's a link to a page which describes some of the obvious (and not so obvious) things which people try to validate, which can trip them up:

http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/

如果您要允许任何人到您的网站上,那么最好的方法是强制最大字段长度您在数据库中分配的空间。即使这样,你也会惹恼某人。

If you want to allow anybody onto your site, then the best you can really hope for is to force a maximum field length to fit the space you've allocated in your database. Even then you're going to annoy someone.

这篇关于如何“验证” CakePHP中的人名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆