Javascript正则表达式:测试人的名字 [英] Javascript regex: test people's name

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

问题描述

从这些问题: javascript正则表达式:只允许使用英文字母

如何对人名进行表达式测试?目前它根本不允许名称之间的空格。我需要能够匹配 John Doe

How can I make that expression test for people's name? Currently it doesn't allow spaces between names at all. I need to be able to match something like John Doe

干杯

推荐答案

let result = /^[a-zA-Z ]+$/.test( 'John Doe');
console.log(result);

丢弃任何符号你需要在角色类。这是为什么我说具体关于完全您要验证的内容。这个正则表达式不会考虑重音字符,如果你关心你最好用unicode匹配。

Throw any symbols you need in the character class. This is why I said be specific about exactly what you want to validate. This regex will not account for accented characters, if you care about that you'd most likely better go with unicode matching.

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

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