Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

javascript - Regular Expression for alphabets with spaces

I need help with regular expression. I need a expression which allows only alphabets with space for ex. college name.

I am using :

var regex = /^[a-zA-Z][a-zA-Z\s]+$/;

but it's not working.

question from:https://stackoverflow.com/questions/9289451/regular-expression-for-alphabets-with-spaces

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just add the space to the [ ] :

var regex = /^[a-zA-Z ]*$/;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...