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

查看:34
本文介绍了如何“验证"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天全站免登陆