字母字符和空格的Javascript正则表达式? [英] Javascript regex for alphabetic characters and spaces?
问题描述
我需要包含a-z,A-Z和空格的javascript正则表达式
I need a regex for javascript that includes a-z, A-Z, and spaces
例如,将接受字符串鲍勃说嗨",但不接受有四个小丑"
For example, the string "Bob says Hi" would be accepted, but not "There were 4 clowns"
我得到的最接近的是/^ [a-zA-Z] + $/
,其中包括a-z和A-Z,但不包含空格.
The closest I've gotten is /^[a-zA-Z]+$/
which includes a-z and A-Z but not spaces.
推荐答案
/^ [A-Za-z] + $/
或/^ [A-Za-z \ s] + $/
更多好东西在这里:
http://www.regular-expressions.info/javascript.html
或仅/\ w + $/
(如果您还希望使用0-9和下划线(\ w代表文字字符",通常是 [A-Za-z0-9 _]
).但是您最近的编辑表明您不想要0-9,所以请使用上面的前2个.
or just /\w+$/
if you also want 0-9 and underscores (\w stands for "word character", usually [A-Za-z0-9_]
). But your recent edit indicates that you dont want 0-9, so use one of the first 2 above.
这篇关于字母字符和空格的Javascript正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!