所有字母中带空格的所有字母的正则表达式 [英] Regular Expression for all letters in all alphabets with spaces exept anything else

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

问题描述

我正在尝试使用jQuery创建名称字段过滤器,并且尝试了太多的正则表达式,但它们中的任何一个都无法正常工作.

I'm trying to make a name field filter with jQuery and I tried so many regular expressions and no of them work fully.

我需要做的就是将名称字段作为名称字段-别的,例如例如,亚当·杰里米·史密斯(Adam Jeremy Smith).因此,不可能输入$或/或_或〜或0-9或其他任何东西吗?该怎么做?

All I need is to make the name field as the name field - nothing else, e.g. Adam Jeremy Smith for example. So there would be no possibility to type $ or / or _ or ~ or 0-9 or anything else? How to do this?

我认为应该是:

/[^\\p{L}]+([^0-9])+$/

是的,仅当您输入例如"Adam Je4",但是如果您继续写"Adam Je4remy",则无法正常工作并验证错误吗?

Yeah it works only if you type e.g. 'Adam Je4' but if you continue and write 'Adam Je4remy' it doesn't work and validates it incorrectly?

如何实现?

推荐答案

如果将名称定义为something that consists of 1 or more words, separated by spaces, where each word consists of one or more letters, and starts with uppercase,则其写法类似于...

If you define name as something that consists of 1 or more words, separated by spaces, where each word consists of one or more letters, and starts with uppercase, it's written something like...

/^[A-Z][a-z]+(\s+[A-Z][a-z]+)*$/

但这实际上要复杂得多,请参阅-它不仅涉及字母(在您的示例中为\p{L};顺便说一句,JS不支持属性unicode类,您必须使用插件(例如

But it's actually much more complicated, see - and it's not only about letters (\p{L} in your example; btw, property unicode classes are not supported by JS, you have to use plugins (like this one, for example) to implement such functionality).

例如,您是否允许在名称中使用撇号?如果是这样,将如何使用它们(大概没有一个名字的两个撇号都像这样-I''van Ivanov?连字符呢?不同的大写规则呢:您会考虑使用

For example, will you allow apostrophes in your names? If so, how can they be used (probably no name has two apostrophes close, like this - I''van Ivanov? What about hyphens? What about different capitalization rules: will you consider brian d foy a true name, for example? And so on...

关键是您必须平衡您实际期望看到的与正则表达式的复杂性.

The point is you have to balance what you actually expect to see with the complexity of your regex.

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

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