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
Post a Comment