且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式用法

更新时间:2022-09-05 23:13:24

验证手机号的合法性:

1
2
3
4
5
6
7
8
9
10
11
12
13
public class PhoneNumCheck {
public static void main(String[] args) {
String handset = "18217968050";
System.out.println(check(handset));
}
private static String check(String handset) {
String regex = "^13\\d{9}|15\\d{9}|18\\d{9}$";
if(handset.matches(regex)) {
return handset +"\n 是合法的手机号";
}
return handset + "\n 不是合法的手机号";
}
}

 



      本文转自arac 51CTO博客,原文链接:http://blog.51cto.com/skyarac/1345764,如需转载请自行联系原作者