Java tutorial
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isPhoneNumberValid(String phoneNumber) { if ((phoneNumber == null) || (phoneNumber.trim().equals(""))) { return false; } boolean isValid = false; String expression_r_r = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$"; Pattern pattern = Pattern.compile(expression_r_r); Matcher matcher = pattern.matcher(phoneNumber); if (matcher.matches()) { isValid = true; } return isValid; } }