简体   繁体   中英

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,

example string Björk Guð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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM