简体   繁体   English

javascript正则表达式允许名称带有一个空格和特殊字母

[英]javascript regular expression allow name with one space and special Alphabets

how to write regular expression allow name with one space and special Alphabets? 如何编写正则表达式,允许名称带有一个空格和特殊字母? I tried with this [a-zA-Z]+(?:(?:\\. |[' ])[a-zA-Z]+)* but not working for me, 我尝试使用此[a-zA-Z]+(?:(?:\\. |[' ])[a-zA-Z]+)*但对我不起作用,

example string Björk Guðmundsdóttir 示例字符串BjörkGuðmundsdóttir

You may try something along these lines: 您可以尝试以下方法:

^(?!.*[ ].*[ ])[ A-Za-zÀ-ÖØ-öø-ÿ]+$

The first negative lookahead asserts that we do not find two spaces in the name. 首次出现负先行断言,我们没有找到名字两个空格。 This implies that at most one space is present (or no spaces at all). 这意味着最多存在一个空间(或根本没有空间)。 Then, we match any number of alphabets, with most accented letters included. 然后,我们将匹配任意数量的字母,其中包括最强调的字母。 Spaces can also be matched, but the lookahead would already ensure that at most one space can be present. 空间也可以匹配,但是超前已经可以确保最多存在一个空间。

Demo 演示

Use this one: 使用这个:

 [a-zA-Z\À-\ÿ]*[ ]{1}[a-zA-Z\À-\ÿ]* 

Answer from other question 其他问题的答案

暂无
暂无

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

相关问题 正则表达式,允许字母数字与空格并禁止某些特殊字符(&lt;&gt;&;) - Regular expression to allow alphanumeric with space and disallow certain special characters(<>&;) javascript正则表达式,至少3个字并允许特殊字符 - javascript regular expression of minimum 3 words and allow special characters 使用xregexp的javascript正则表达式替换特殊字符,但允许白名单 - javascript regular expression to replace special characters, but allow a whitelist, using xregexp 使用正则表达式(JavaScript)删除一个空格字符 - Remove One Space Character with a Regular Expression (JavaScript) 使用正则表达式验证javascript中通用字母的输入 - Validate input with regular expression for universal alphabets in javascript javascript正则表达式匹配排除空格和特殊字符 - javascript regular expression match exclude space and special charcters 正则表达式只允许字母和特殊字符,开头没有空格 - regex to allow only alphabets and no special characters, with no space at the beginning Javascript 只允许字母表、空格和 - 的正则表达式 - Javascript regular expression that allow only alphabet, space and - only 正则表达式在开始或结束时没有空格,但允许中间有空格但也只允许一个字符输入 - Regular expression for no space at start or end, but allow space in middle but also allow only one char inputs 带空格的字母的正则表达式 - Regular Expression for alphabets with spaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM