简体   繁体   English

允许字母字符,空格,破折号,撇号和长度<= 50

[英]Allow alpha characters, space, dash, apostrophe and length <= 50

I'm trying to write regular expression that allows alpha characters, space, dash, apostrophe and length 50. So far I have this: 我正在尝试编写允许字母字符,空格,破折号,撇号和长度为50的正则表达式。到目前为止,我有以下内容:

/^([A-Za-z\s].{1,50})$/

I'm not sure where I should place the code for dash and apostrophe. 我不确定应该在哪里放置破折号和撇号的代码。 If anyone can help pleases let me know. 如果有人可以帮助,请告诉我。 Thanks. 谢谢。

You need 你需要

/^[A-Za-z '-]{1,50}$/

or 要么

/^[A-Za-z\s'-]{1,50}$/

When you use \\s instead of a space, you will allow any whitespace. 当使用\\s代替空格时,将允许任何空格。

The apostrophe can be placed anywhere inside the character class (so as not to ruin the ranges), and the hyphen at the start/end of the character class does not need to be escaped. 撇号可以放置在字符类内部的任何位置(以免破坏范围),并且无需转义字符类开头/结尾的连字符。

If you use {1,50} limiting quantifier , it means you allow 1 to 50 chars of the type specified in the character class. 如果使用{1,50} 限制量词 ,则表示您允许1到50个字符类中指定类型的字符。 If you allow exactly 50 chars, use /^[A-Za-z\\s'-]{50}$/ . 如果您恰好允许50个字符,请使用/^[A-Za-z\\s'-]{50}$/ If you use just + instead, you will allow 1 or more characters. 如果仅使用+ ,则允许1个或多个字符。

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

相关问题 Javascript 验证仅允许使用 Alpha 字符、连字符 (-)、点 (.)、撇号 (&#39;) 和空格 - Javascript validation to allow only Alpha characters, hyphen (-), dot (.), apostrophe ('), and space 如何使用键码验证来保留字母数字字符的空间? - How to allow space with alpha numeric characters using keycode validation? 正则表达式只允许两个字,一个空格,最多50个字符 - Regex to allow only two words, one space and limit to 50 characters Angular JS指令,该指令将允许字母字符并包括大写锁定和空格 - Angular js directive that would allow alpha characters and would include capslock and space 如何使用破折号 -、撇号 &#39; 或空格来大写名称? - How can I uppercase names with a dash -, apostrophe ' or space? 如何在文本框中允许所有字母/空格/单引号/破折号 - How to allow all alphabets/space/single quotation/dash in a textbox 输入文本框字段仅允许字符,不允许数字,但允许空格? - Input textbox field allow only characters not allow numeric but allow space? 允许正则表达式中的(破折号)和(数字)用于非英语字符 - Allow (dash) & (numbers) in regex for NON-English characters 如果长度大于x,jQuery在字符之间添加破折号 - jquery add dash between characters if length is greater than x ng-pattern允许使用字母和某些特殊字符 - ng-pattern to allow alpha and certain special characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM