public static boolean isPhoneNumberValid(String phoneNumber) { boolean isValid = false; /* * 可接受的电话格式有: */ String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$"; /* * 可接受的电话格式有: */ String expression2 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$"; CharSequence inputStr = phoneNumber; Pattern pattern = Pattern.compile(expression); Matcher matcher = pattern.matcher(inputStr); Pattern pattern2 = Pattern.compile(expression2); Matcher matcher2 = pattern2.matcher(inputStr); if(matcher.matches() || matcher2.matches()) { isValid = true; } return isValid; }
判断是否是电话号码
猜你喜欢
转载自201304154519.iteye.com/blog/1997752
今日推荐
周排行