Java examples for java.util.regex:Match Phone Number
check Phone number with regex
//package com.java2s; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String phone = "java2s.com"; System.out.println(checkPhone(phone)); }/* ww w . j a va 2 s. co m*/ public static boolean checkPhone(String phone) { if (phone.equals("")) return true; else { String regex = "^1\\d{10}$"; return Pattern.matches(regex, phone); } } }