Android 功能代码摘录
判断是否是电话号码:
public static boolean isPhoneNumber(String text) { char[] sChar = text.toCharArray(); for (char c : sChar) { if (checkCharacter(c)) { continue; } else { return false; } } return true; } public static String filterNumbers(String originalText) { StringBuffer buffer = new StringBuffer(originalText); for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); if (checkCharacter(c)) { continue; } else { buffer.deleteCharAt(i); } } return buffer.toString(); } private static boolean checkCharacter(char c) { return ((c >= '0' && c <= '9') || c == ',' || c == ';' || c == '*' || c == '#' || c == '+' || c == '-' || c == '(' || c == ')' || c == ',' || c == '/' || c == 'N' || c == '.' || c == ' ' || c == ';'); }
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论