public class MainClass
{
public static void main( String[] args )
{
System.out.println(validateCity("Street"));
System.out.println(validateState("CA"));
}
// validate city
public static boolean validateCity( String city )
{
return city.matches( "([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)" );
} // end method validateCity
// validate state
public static boolean validateState( String state )
{
return state.matches( "([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)" ) ;
} // end method validateState
}
|