Java tutorial
//package com.java2s; public class Main { public static String formatPhone(String number) { StringBuffer sb = new StringBuffer(); char c; for (int i = 0; i < number.length(); i++) { c = number.charAt(i); if (48 <= c && c <= 57) sb.append(c); } return sb.toString(); } }