例子:
import java.util.regex.Matcher; import java.util.regex.Pattern; public class tel ... { public boolean isNumeric(String str)...{ Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); if( !isNum.matches() )...{ return false; } return true; } private String toNo(String telno)...{ String temp=""; int j=0; if(isNumeric(telno)) ...{ return telno; } else...{ for(int i=0;i<telno.length();i++)...{ if(!(Character.isDigit(telno.charAt(i))))...{ continue; } else ...{ temp += telno.charAt(i); } } } return temp; } public static void main(String[] args)...{ tel test = new tel(); String no="0592-3924063"; String no2="(0592)3924063"; String no3="05923924063"; System.out.println(test.toNo(no)); System.out.println(test.toNo(no2)); System.out.println(test.toNo(no3)); }}