hello_java
hello_java

Reputation: 101

What is the regex for : Allow only letters and spaces but not start with space?

I'm writing a program that let people enter their infomation (name, age....) .For the name input I don't want them to left blank and allow only letters and spaces but not start with space. What is the appropriate regex? I tried with : ^[a-zA-Z\\s]*$ but it didn't work. Thanks!

Upvotes: 0

Views: 442

Answers (3)

j3ny4
j3ny4

Reputation: 441

^([a-zA-Z]+\s*)+$ should do the job

Upvotes: 1

jithinpt
jithinpt

Reputation: 1244

Try this: ^[a-zA-Z][a-zA-Z\s]*$

Upvotes: 2

Mureinik
Mureinik

Reputation: 311393

You should specify the first character separately:

^[a-zA-z][a-zA-Z\\s]*$

Upvotes: 3

Related Questions