Here you can find the source of getPlainPhoneNumber(String phoneNumber)
Parameter | Description |
---|---|
phoneNumber | a parameter |
public static String getPlainPhoneNumber(String phoneNumber)
//package com.java2s; public class Main { /**//from w w w. j av a 2 s. c o m * Convert a formatted phone number into a plain digit-only * phonumber * @param phoneNumber * @return empty string if failed. */ public static String getPlainPhoneNumber(String phoneNumber) { if (phoneNumber == null || phoneNumber.isEmpty()) return ""; String newPhoneNumber = new String(phoneNumber); newPhoneNumber = newPhoneNumber.replace(" ", ""); newPhoneNumber = newPhoneNumber.replace("(", ""); newPhoneNumber = newPhoneNumber.replace("-", ""); newPhoneNumber = newPhoneNumber.replace(")", ""); newPhoneNumber = newPhoneNumber.replace("+", ""); if (!newPhoneNumber.startsWith("1")) { newPhoneNumber = "1" + newPhoneNumber; } return newPhoneNumber; } }