public static boolean isLetterDigit(String str){ boolean isDigit = false;//Define a boolean value to indicate whether it contains a number boolean isLetter = false;//Define a boolean value to indicate whether it contains letters for(int i=0 ; i if(((i))){ //Judge each character by judging numbers in the char wrapper class isDigit = true; } if(((i))){ //Judge each character using the method of judging letters in the char wrapper class isLetter = true; } } String regex = "^[a-zA-Z0-9]+$"; boolean isRight = isDigit && isLetter&&(regex); return isRight; }
Android method to determine whether the numbers, Chinese or letters entered by EditText
String txt = ().toString(); Pattern p = ("[0-9]*"); Matcher m = (txt); if(() ){ (,"The input is a number", Toast.LENGTH_SHORT).show(); } p=("[a-zA-Z]"); m=(txt); if(()){ (,"The letters are entered", Toast.LENGTH_SHORT).show(); } p=("[\u4e00-\u9fa5]"); m=(txt); if(()){ (,"The Chinese characters are entered", Toast.LENGTH_SHORT).show(); }