Java examples for java.util.regex:Match Phone Number
is string a Validate Phone in format (123)-123-1234
//package com.java2s; public class Main { public static void main(String[] argv) { String str = "java2s.com"; System.out.println(isValidatePhone(str)); }//w ww .j av a 2 s .c o m public static final String REGEX_PHONE = "(\\d{4}-|\\d{3}-)?(\\d{8}|\\d{7})"; public static boolean isValidatePhone(String str) { return isValidate(str) && str.matches(REGEX_PHONE); } public static boolean isValidate(String str) { return str != null && str.equals("") == false && !str.equalsIgnoreCase("null");// null?????????? } }