javascript 正则表达式 - 允许使用字母、撇号、句号、逗号和连字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13254831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:12:45  来源:igfitidea点击:

Regular Expression - letters, apostrophes, full stops, commas and hyphens are allowed

javascriptjavajqueryhtmlregex

提问by user869375

I am scratching my head around for this small yet confusing requirement that I have.

我正在为这个小小的但令人困惑的要求而挠头。

I need a regular expression for the name field which only allows letters, apostrophes, full stops, commas and hyphens. Name field also should not allow more than 150 characters.

我需要一个 name 字段的正则表达式,它只允许字母、撇号、句号、逗号和连字符。名称字段也不得超过 150 个字符。

Any help would be much appreciated!

任何帮助将非常感激!

回答by ?mega

Use regex pattern

使用正则表达式

^[a-zA-Z'.,-]{0,150}$

If minimum length is also required, replace 0with such number...

如果还需要最小长度,请替换0为这样的数字...