Checks if the String contains only unicode letters, digits or space ' '.
isAlphanumeric(null) = false isAlphanumeric("") = true isAlphanumeric(" ") = true isAlphanumeric("abc") = true isAlphanumeric("ab c") = true isAlphanumeric("ab2c") = true isAlphanumeric("ab-c") = false
public class Main { public static void main(String[] argv) throws Exception { String str = "demo2s.com"; System.out.println(isAlphanumericSpace(str)); }// ww w . ja v a 2 s. c o m public static boolean isAlphanumericSpace(String str) { if (str == null) { return false; } int sz = str.length(); for (int i = 0; i < sz; i++) { if ((Character.isLetterOrDigit(str.charAt(i)) == false) && (str.charAt(i) != ' ')) { return false; } } return true; } }