java - regex not working as expected for full name -


i have textbox taking input full name.

when user enter input my name, don't error. when user enter input my name is, error.

regex have is

([a-za-z]+|[a-za-z]+\\s[a-za-z]+) 

what want is, text should have

only (a-z or a-z) , white space... 

demo inputs are

  1. my name xyz pqr stu
  2. my name xyz
  3. xyz pqr stu

how can done using regex?

update 1

i using

 pattern p = pattern.compile("[a-za-z\\s]"); matcher m = p.matcher("dummyname"); boolean matchfound = m.matches(); 

still getting matchfound false

\s whitespace. if want allow whitespace in character class upper , lowercase letters, use [a-za-z\s].


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -