Android Phone Number Format formatPhoneNumber(String number)

Here you can find the source of formatPhoneNumber(String number)

Description

Formats a number stripping it from any non digit except for a leading plus sign

Parameter

Parameter Description
number a parameter

Declaration

public static String formatPhoneNumber(String number) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w  w  . j av a2s  . c  om*/
     * Formats a number stripping it from any non digit except for a leading plus sign
     * @param number
     * @return
     */
    public static String formatPhoneNumber(String number) {
        if (number != null) {
            String strippedNumber = number.replaceAll("\\D", "");
            if (number.startsWith("+")) {
                return "+" + strippedNumber;
            } else {
                return strippedNumber;
            }
        }
        return null;
    }
}

Related

  1. formatPhoneNumber(String phoneNumber)
  2. formatPhoneNumber(String numberString)
  3. formatPhone(String phone)
  4. formatPhone(String phone, String format)