正则表达式验证名称 [英] Regex to validate names

查看:63
本文介绍了正则表达式验证名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个验证人名的正则表达式.应该允许这些:

I would like to create a regex which validates a name of a person. These should be allowed:

  • 字母(大写和小写)
  • -
  • 空格

创建正则表达式非常容易.问题是有些人还在他们的名字中使用了特殊字符.例如,假设用户名为 gûnther 或 François.有很多字符,如 û 和 ç 可用,很难列出所有这些.

This is pretty easy to create a regex for. The problem is that some people also use special characters in their names. For example, assume a user named gûnther or François. There are a lot of characters like û and ç available and it's hard to list all of these.

是否有一种简单的方法可以检查人名是否正确?

Is there an easy way to check for correct human names?

推荐答案

是否有一种简单的方法可以检查人名是否正确?

Is there an easy way to check for correct human names?

这个问题已经讨论过多次了.我相当肯定,人们唯一可以同意的是,为了存在,名称不能是空字符串,因此:

This has been discussed several times. I'm fairly certain that the only thing that people can agree on is that in order to exist a name cannot be a empty string, thus:

^.+$

(是的,我知道这可能不是 OP 想要的.我只是总结了之前的问答.)

(Yes, I am aware that this is probably not what OP is looking for. I'm just summarizing earlier Q&As.)

这篇关于正则表达式验证名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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