Android examples for java.lang:String Strip
Formats a number stripping it from any non digit except for a leading plus sign
import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; public class Main{ /**//ww w.ja va2s . c o m * 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; } }