简体   繁体   English

regexp-javaScript的姓氏和名字

[英]regexp - first and last name javaScript

I'm trying to make a JavaScript regexp such as the facebook uses for real names: 我正在尝试制作一个JavaScript正则表达式,例如facebook用于实名:

    Names can't include: 名称不能包括:
  • Symbols 符号
  • numbers 数字
  • unusual capitalization 大写
  • repeating characters or punctuation 重复字符或标点符号

source: Facebook help center 来源:Facebook帮助中心
Here is my regexp: 这是我的正则表达式:

 /^[a-z \,\.\'\-]+$/i

The problem with this regexp is that it doesn't check for repeated characters or punctuation: 此正则表达式的问题在于它不检查重复的字符或标点符号:
then I found this : 然后我发现了这个:

/(.)\1/

so I'm now checking it like this: 所以我现在像这样检查它:

$('input [type=text]).keyup(function(){
var name = $(this).val();
var myregex = /^[a-z\,\.\'\-]+$/i
var duplicate =  /(.)\1/
if(name != myregex.exec(name) ||  name == /(.)\1/)
{// the name entered is wrong
}
else
//the name is ok

but the problem I'm facing is with inputs like: 但是我面临的问题是像这样的输入:

  • Moore 摩尔
  • Callie 卡丽
  • Maggie 劣质煤

what can I do to get the problem solved? 我该怎么做才能解决问题?

You should stop trying to solve this problem: 您应该停止尝试解决此问题:

  • It is very complicated 非常复杂
  • Names are very personal 名字很私人

For instance your system will never be able to validate names from China or Japan.... (For instance: Børre Ørevål ,汉/漢 ) 例如,您的系统将永远无法验证来自中国或日本的名称。...(例如:BørreØrevål,汉/汉)

So just leave the whole idea, and let people freely enter their names with no restrictions. 因此,只剩下整个想法,让人们自由输入自己的名字而不受限制。

Related: Regular expression for validating names and surnames? 相关: 用于验证名称和姓氏的正则表达式?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM