List of utility methods to do Phone Number Format
String | formatPhoneNumber(String phoneNumber) Format plain phone number into a formatted string if (phoneNumber == null || phoneNumber.isEmpty() || phoneNumber.length() < 10) { return phoneNumber; char[] chars = phoneNumber.toCharArray(); StringBuilder sb = new StringBuilder(); if (chars.length == 10) { sb.append("(" + chars[0]); ... |
String | formatPhoneNumber(String number) Formats a number stripping it from any non digit except for a leading plus sign if (number != null) { String strippedNumber = number.replaceAll("\\D", ""); if (number.startsWith("+")) { return "+" + strippedNumber; } else { return strippedNumber; return null; |
String | formatPhoneNumber(String numberString) format Phone Number numberString = numberString.replaceAll("[^0-9]+", ""); int i = numberString.length(); if (i <= 10) return numberString; else return numberString.substring(i - 10); |
String | formatPhone(String phone) format Phone return formatPhone(phone, null);
|
String | formatPhone(String phone, String format) format Phone if (isNullOrEmpty(phone)) { return phone; String s = ""; char[] cs = getDigit(phone).toCharArray(); int i = 0; if (isNullOrEmpty(format)) { if (cs[0] == '1') { ... |