美文网首页
正则表达式判断电话号码

正则表达式判断电话号码

作者: 中王之王 | 来源:发表于2018-04-11 00:07 被阅读4次

用到两个类 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();
}
}

相关文章

网友评论

      本文标题:正则表达式判断电话号码

      本文链接:https://www.haomeiwen.com/subject/asvohftx.html