简体   繁体   中英

Regular expression which allow only characters or space

I need help with regular expression.I need a expression in jquery which allows only character or space between two words. no double space allowed

I am using this

/^[a-zA-Z]+(-_ [a-zA-Z]+)*/

but it's not working.

Example space hello - not allowed

hello space - not allowed

hello space space hello - not allowed

space hello space - not allowed

hello1234 - not allowed

hello space 1234 - not allowed


hello world-allowed

hello-allowed

hello how are you-allowed

你可以用它

/^([a-zA-Z]+\s)*[a-zA-Z]+$/

I see you already have an accepted answer, but here's another, more concise option:

/^\w+( \w+)*$/

Starts with a word, then followed by any number of words with a single space in front.

Note that this accepts numbers in words too. I don't know if that's what you want.

这个RegEx对我有用([A-Za-z] () [A-Za-z] +)

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