List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:Main.java
public static String getOnlyNumerics(String str) { if (str == null) return null; StringBuilder strBuff = new StringBuilder(); char c;//from w w w . ja v a2 s . c o m for (int i = 0; i < str.length(); i++) { c = str.charAt(i); if (Character.isDigit(c)) strBuff.append(c); } return strBuff.toString(); }
From source file:Main.java
public static String getOnlyNumerics(String str) { if (str == null) { return null; }//from w w w. java 2 s. co m StringBuffer strBuff = new StringBuffer(); char c; for (int i = 0; i < str.length(); i++) { c = str.charAt(i); if (Character.isDigit(c)) { strBuff.append(c); } } return strBuff.toString(); }
From source file:Main.java
public static String shortName(String hostname) { if (hostname == null) return null; int index = hostname.indexOf('.'); if (index > 0 && !Character.isDigit(hostname.charAt(0))) return hostname.substring(0, index); else// www. j a v a2 s .c o m return hostname; }
From source file:Main.java
public static String getOnlyNumerics(String input) { if (input == null) return null; StringBuilder strBuff = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (Character.isDigit(c)) strBuff.append(c);/*from ww w.jav a 2 s .c o m*/ } return strBuff.toString(); }
From source file:Main.java
public static String toPersianNumbers(String str) { char[] persianNumbers = { '\u06F0', '\u06F1', '\u06F2', '\u06F3', '\u06F4', '\u06F5', '\u06F6', '\u06F7', '\u06F8', '\u06F9' }; StringBuilder builder = new StringBuilder(); for (int i = 0; i < str.length(); i++) { if (Character.isDigit(str.charAt(i))) { builder.append(persianNumbers[(int) (str.charAt(i)) - 48]); } else {/*from ww w . j a v a2s . com*/ builder.append(str.charAt(i)); } } return builder.toString(); }
From source file:Main.java
public static String getOnlyNumerics(String str) { if (str == null) { return null; }//from w ww . j av a 2 s . c om StringBuilder strBuff = new StringBuilder(); char c; for (int i = 0; i < str.length(); i++) { c = str.charAt(i); if (Character.isDigit(c)) { strBuff.append(c); } } return strBuff.toString(); }
From source file:Main.java
public static boolean containsOnlyNumbers(String str) { if (str == null || str.length() == 0) { return false; }//from ww w . j a va2 s.co m //Replace '-' str = str.replaceAll("-", ""); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '.') continue; if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
From source file:Main.java
public static boolean isPrintable(char c) { if (Character.isJavaIdentifierStart(c)) { // Letters and $ _ return true; }//from w w w . j ava 2 s . com if (Character.isDigit(c)) { return true; } switch (Character.getType(c)) { case Character.MODIFIER_SYMBOL: return true; // ` ^ case Character.DASH_PUNCTUATION: return true; // - case Character.MATH_SYMBOL: return true; // = ~ + | < > case Character.OTHER_PUNCTUATION: return true; // !@#%&*;':",./? case Character.START_PUNCTUATION: return true; // ( [ { case Character.END_PUNCTUATION: return true; // ) ] } } return false; }
From source file:Main.java
public static boolean isRegistrationValid(String email) { if (email.length() != 11) return false; for (int i = 0; i < email.length(); i++) { if (i == 9) { if (email.charAt(i) != '-') return false; } else {/*from w w w . ja v a2 s . c o m*/ if (!Character.isDigit(email.charAt(i))) return false; } } return true; }
From source file:Main.java
private static String getNumericPrefix(String string) { StringBuffer numeric = new StringBuffer(); if (string != null) { string = string.trim();/* w ww . ja va2s .com*/ if (string.length() > 0) { StringBuffer buffer = new StringBuffer(string); char first = buffer.charAt(0); if (Character.isDigit(first)) { numeric.append(first); for (int i = 1; i < buffer.length(); i++) { Character next = buffer.charAt(i); if (Character.isDigit(next)) { numeric.append(next); // skip commas within numbers } else if (next.equals(',')) { continue; } else { break; } } } } } return numeric.length() == 0 ? null : numeric.toString(); }