826220679@qq.com
2025-08-07 0e0e51fc63a865977d751271be28437e24dd6a99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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); // ¿Õ°²È«¼ì²â
    }
}