用到两个类 Pattern 和Matcher 。。
public class InputUtil {
public static boolean isPhone(String str){
Pattern phone = Pattern.compile("1\d{10}");
Matcher m = phone.matcher(str);
return m.matches();
}
public static boolean isNumber(String str){
Pattern phone = Pattern.compile("\d+");
Matcher m = phone.matcher(str);
return m.matches();
}
public static boolean isString(String str){
Pattern phone = Pattern.compile("\w+");
Matcher m = phone.matcher(str);
return m.matches();
}
}
网友评论