简体   繁体   English

javascript正则表达式,至少3个字并允许特殊字符

[英]javascript regular expression of minimum 3 words and allow special characters

I have the following regex that validates if it's a minimum of 3 words: 我有以下正则表达式可验证是否至少3个单词:

 "minimumThreeWordsAndNoURL": {
                    "regex": /^(\b\w+\b\s?){3,}$/,
                    "alertText": "Too short"
                },

Now the issue is that when I do 'How much is this?' 现在的问题是,当我执行“这是多少?” it fails because of the special characters. 由于特殊字符而失败。 How do I allow special characters in this regex? 如何在此正则表达式中允许特殊字符?

这是您想要的吗?

 /(\b\S+.*?){3,}/.test('How much is this?')

The following regex should work: 以下正则表达式应该起作用:

^(?:(?:^| )\S+ *){3,}$

Online Demo 在线演示

试试这个未经测试的:

(\b.{3,}\b\s)+

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

相关问题 JavaScript正则表达式-仅接受两个不带特殊字符的单词 - JavaScript Regular Expression - Accept only two words with no special characters 使用xregexp的javascript正则表达式替换特殊字符,但允许白名单 - javascript regular expression to replace special characters, but allow a whitelist, using xregexp 正则表达式允许数字或特殊字符 - Regular expression to allow either number or special characters 不允许特殊字符的 Javascript 正则表达式 - Javascript Regular Expression that diallows special characters javascript-正则表达式字母数字和特殊字符 - javascript- regular expression alphanumeric and special characters 用于识别所有特殊字符的javascript正则表达式 - javascript regular expression to recognize all special characters 使用javascript删除特殊字符的正则表达式 - Regular expression using javascript for removing the special characters 正则表达式,允许字母数字与空格并禁止某些特殊字符(&lt;&gt;&;) - Regular expression to allow alphanumeric with space and disallow certain special characters(<>&;) 如何使用 ( ) [ ] 大括号允许作为密码正则表达式中的特殊字符? - How to use ( ) [ ] braces to allow as special characters in password regular Expression? javascript正则表达式允许名称带有一个空格和特殊字母 - javascript regular expression allow name with one space and special Alphabets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM