Here you can find the source of formatPhoneNumber(String phoneNumber)
public static String formatPhoneNumber(String phoneNumber)
//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 ""; } } }