/**
* 限制判断是否为纯数字或纯字母或数字加字母组合
*
* @param str 字符串
*/
public static boolean isNumbersAndLetters(String str) {
if (str == null || str.isEmpty()) {
return true;
}
boolean isAlpha = str.matches("^[a-zA-Z]+$");
boolean isNumeric = str.matches("^[0-9]+$");
boolean isAlphaNumeric = str.matches("^[a-zA-Z0-9]+$");
if (isAlpha) {
return true; // 纯字母
} else if (isNumeric) {
return true; // 纯数字
} else if (isAlphaNumeric) {
return true; // 数字和字母组合
} else {
return false; // 其他情况,包含中文或特殊字符
}
}
Android 判断字符是否为数字+字母
最新推荐文章于 2024-08-18 03:35:42 发布