如何验证人名? -Python / Django [英] How to validate person names? - Python/Django

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

问题描述

我希望为我的一种表格的全名创建一个验证器。

不幸的是,我不确定最好的方法是,

Unfortunately I am not sure the best way to go on about is, as it is not as trivial as:

if not char in string.letters + " .'":
    raise ValidationError("...")

正则表达式可以正常工作,但 \w [:alpha:] [a-zA-Z ] 并没有真正捕获特殊字符。

Thought a regex would work, but \w, [:alpha:], [a-zA-Z] don't really capture special characters.

名称示例:


  • Tiësto

  • Tiësto

玛丽·约瑟夫

玛丽·弗朗索瓦

何塞·德·里巴斯

有什么想法吗?

推荐答案

我个人不会担心验证名称,我猜它有很多可能性很难维护。如果您能提出一个正则表达式,我认为它太通用了,将无效。我唯一认为有价值的是排除 @#$%^ 之类的东西。

I personally wouldn't bother about validating names, I guess there are so many possiblities it is very hard to maintain. If you could come up with a regular expression, I think it would be so generic it wouldn't be effective. The only thing I can think of as valuable is excluding things like @ # $ % ^.

只要确保您正在转义字符,如果某人的名字是Fooalert('lala'),那很好,但是请确保未对其进行解析。

Just make sure you are escaping characters, if someone's name is Fooalert('lala'), that's fine, but make sure it's not parsed.

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

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