1.使用正则删除非数字
str = str.replaceAll("\\D+","");
2.Google Guava
CharMatcher.inRange('0','9').retainFrom("123-456-789")
或
String input = "My phone number is 123-456-789!";
String output = CharMatcher.is('-').or(CharMatcher.DIGIT).retainFrom(input); // output 123-456-789