Java Number Format formatPhoneNumber(String phoneNumber)

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

Description

format Phone Number

License

Open Source License

Declaration

public static String formatPhoneNumber(String phoneNumber) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatPhoneNumber(String phoneNumber) {
        try {/*from  ww w.j ava 2  s . c o  m*/
            String s = phoneNumber.replaceAll("\\(|\\)|:|-|\\.", "");
            ;
            s = s.replaceAll("(\\d{3})(\\d{3})(\\d{4})(\\d{3})*", "($1) $2-$3x$4");

            if (s.endsWith("x"))
                s = s.substring(0, s.length() - 1);
            return s;
        } catch (Exception ex) {
            return "";
        }
    }
}

Related

  1. formatPct(final Number amount)
  2. formatPercentage(Number numerator, Number denominator)
  3. formatPhone(String phoneNumber, String formattingPattern, String countryCode)
  4. formatPhoneNo(String country, String area, String number, String inline)
  5. formatPhoneNumber(String number)
  6. formatPrintIntegerToString(long number, boolean printCommasP, boolean printSignP, int radix, int mincol, char padchar, char commachar, int commainterval)
  7. formatRowKey(final long number, final int digits, byte[] dest)
  8. formatSafetyNumber(String digits)
  9. formatSheetNumber100(final int sheetNumber)