A regular expression is a pattern of characters that describes a set of strings.
You can use the java.util.regex package to find, display, or modify some or all
of the occurrences of a pattern in an input sequence. The simplest form of a
regular expression is a literal string, such as "Java" or "programming." Regular
expression matching also allows you to test whether a string fits into a
specific syntactic form.
/* should take only any of the following four pattrens: 9999999999999 999-999-999-9999 999-999-9999 9999999999 */ public static boolean validatePhoneNumber(String phNumber) { boolean valResult = false; String numPattern = "[0-9]{10}||[0-9]{13}||[0-9]{3}-[0-9]{3}-[0-9]{3}-[0-9]{4}||[0-9]{3}-[0-9]{3}-[0-9]{4}"; Matcher m; m = Pattern.compile(numPattern).matcher(phNumber); System.out.println(m.matches()); valResult = m.matches(); return valResult; }