package publicsWay;
|
import java.util.regex.Pattern;
|
public final class JugeNumber { // Ìí¼Ófinal·ÀÖ¹¼Ì³Ð
|
// ʹÓÃfinalÐÞÊÎÕýÔò³£Á¿
|
private static final String DIGIT_REGEX = "\\d+"; // ´¿Êý×ÖÕýÔò
|
private static final String CONTAIN_DIGIT_REGEX = ".*\\d.*"; // º¬Êý×ÖÕýÔò
|
private static final String LETTER_REGEX = "[a-zA-Z]+"; // ´¿×Öĸ
|
private static final String CONTAIN_LETTER_REGEX = ".*[a-zA-Z].*"; // º¬×Öĸ
|
private static final String CHINESE_REGEX = "^[\u4e00-\u9fa5]+$"; // ´¿ÖÐÎÄÕýÔò
|
private static final String LETTER_DIGIT_REGEX = "^[a-zA-Z0-9]+$"; // ½öº¬×ÖĸÊý×Ö
|
private static final String CHINESE_LETTER_REGEX = "^[\u4e00-\u9fa5a-zA-Z]+$"; // ÖÐÎÄ+×Öĸ
|
private static final String CHINESE_LETTER_DIGIT_REGEX = "^[\u4e00-\u9fa5a-zA-Z0-9]+$"; // ÖÐÎÄ+×Öĸ+Êý×Ö
|
|
// ·½·¨ÃûºÍÂß¼
|
public static boolean isValidInteger(String num, int maxLength) { // ¹¦ÄÜÃ÷È·µÄ·½·¨Ãû
|
return isInteger(num) && num.length() <= maxLength; // ºÏ²¢Ìõ¼þÅжÏ
|
}
|
|
// Ô¤±àÒëÕýÔòÌá¸ßÐÔÄÜ
|
private static final Pattern INTEGER_PATTERN = Pattern.compile("^[-+]?\\d+$"); // Ô¤±àÒëÕûÊýÕýÔò
|
public static boolean isInteger(String str) {
|
return str != null && INTEGER_PATTERN.matcher(str).matches(); // Ìí¼Ónull¼ì²é
|
}
|
|
// ¼ò»¯ÕýÔòµ÷ÓÃ
|
public static boolean isLetterDigit(String str) {
|
return str != null && str.matches(LETTER_DIGIT_REGEX); // Ìí¼Ónull¼ì²é
|
}
|
|
// ÖÐÎļì²â
|
public static boolean isChinese(String con) {
|
return con != null && con.matches(CHINESE_REGEX); // ʹÓÃÍêÕû×Ö·û´®Æ¥Åä
|
}
|
|
// Ìí¼Ónull¼ì²é
|
public static boolean isLetterDigitOrChinese(String str) {
|
return str != null && str.matches(CHINESE_LETTER_DIGIT_REGEX); // ¿Õ°²È«¼ì²â
|
}
|
|
// ºÏ²¢ÕýÔò¼ì²â
|
public static boolean checkChineseLetter(String str) {
|
return str != null && str.matches(CHINESE_LETTER_REGEX); // Ö±½ÓʹÓÃÕýÔòÆ¥Åä
|
}
|
|
// ±êµã¼ì²âÂß¼
|
public static boolean checkPunctuation(String input) {
|
if (input == null) return false; // ¿ÕÖµ´¦Àí
|
return input.length() != input.replaceAll("\\p{P}", "").length(); // Ö±½Ó·µ»Ø±È½Ï½á¹û
|
}
|
|
// ¼ò»¯·½·¨ÊµÏÖ
|
public static boolean isDigit(String str) {
|
return str != null && str.matches(DIGIT_REGEX); // ¿Õ°²È«¼ì²â
|
}
|
|
public static boolean isLetter(String str) {
|
return str != null && str.matches(LETTER_REGEX); // ¿Õ°²È«¼ì²â
|
}
|
|
public static boolean hasDigit(String str) {
|
return str != null && str.matches(CONTAIN_DIGIT_REGEX); // ¿Õ°²È«¼ì²â
|
}
|
|
public static boolean hasLetter(String str) {
|
return str != null && str.matches(CONTAIN_LETTER_REGEX); // ¿Õ°²È«¼ì²â
|
}
|
}
|