I have a textbox where I am taking input as full name.
When user enter input as My Name, I don’t get any error. However when user enter input as My Name Is, I get error.
Regex I have is
([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)
What actually want is, text should have
only (a-z OR A-Z) AND white space...
Demo Inputs are
- My Name is XYZ PQR STU
- My Name is XYZ
- XYZ PQR STU
How this can be done using regex?
Update 1
I am using
Pattern p = Pattern.compile("[a-zA-Z\\s]");
Matcher m = p.matcher("DummyName");
boolean matchFound = m.matches();
still I am getting matchFound as FALSE
\sis for whitespace. If you want to allow whitespace in a character class as well as upper and lowercase letters, you would use[a-zA-Z\s].