java - Regular expression with characters -


i validating city field , accept spaces between words, example "san francisco". right can validate cities of single word.

how improve code?

public static boolean verifycity (context context, string _string) {      pattern pattern_ = pattern.compile("[a-za-z]+[\\s]+");      matcher matcher = pattern_.matcher(_string);     boolean matchfound = matcher.matches();      if (matchfound) return true;     else            return false;    } 

why not allow spaces in range

pattern pattern_ = pattern.compile("[a-z][a-za-z\\s]*[a-za-z]"); 

the other ranges avoid spaces @ beginning or end.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -