开发者

How to validate person names? - Python/Django

I wish to create a validator for full names for one of my forms.

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("...")

Though开发者_如何学Pythont a regex would work, but \w, [:alpha:], [a-zA-Z] don't really capture special characters.

Name examples:

  • Tiësto

  • Marie Josèphe

  • Marie Françoise

  • José de Ribas


Any ideas?

Holy... sounds like I opened a can of worms! Thanks for the great answers.


Don't.

Please, read this carefully: Falsehoods Programmers Believe About Names.


I don't think it is a good idea.

What kind of names would you like to exclude? There is no international list of allowed characters for names and there is not much reason to disallow specific characters.


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 @ # $ % ^.

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


Depending on your version of python it might be re.UNICODE you are looking for?

http://docs.python.org/library/re.html#re.UNICODE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜