Android Utililty Methods Phone Number Format

List of utility methods to do Phone Number Format

Description

The list of methods to do Phone Number Format are organized into topic(s).

Method

StringformatPhoneNumber(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]);
...
StringformatPhoneNumber(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;
StringformatPhoneNumber(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); 
StringformatPhone(String phone)
format Phone
return formatPhone(phone, null);
StringformatPhone(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') {
...