| | |
| | | * @return 证成功返回true,验证失败返回false |
| | | */ |
| | | public static boolean checkAccount(String account) { |
| | | String regex = "[a-zA-Z]\\w{3,19}"; |
| | | String regex = "[a-zA-Z]\\w{2,19}"; |
| | | return account.matches(regex); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 验证密码 |
| | | * |
| | | * @param password 密码只能包含 字母 , 下划线 , 数字,长度必须在3 到 20 之间 |
| | | * @param password 密码只能包含 字母 , 下划线 , 数字,长度必须在6 到 20 之间 |
| | | * @return 证成功返回true,验证失败返回false |
| | | */ |
| | | public static boolean checkPassword(String password) { |
| | | String regex = "[0-9a-zA-Z_]\\w{3,19}"; |
| | | String regex = "[0-9a-zA-Z_]\\w{5,19}"; |
| | | return password.matches(regex); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @Description: 验证yyyy-MM-dd字符串的正则表达式 |
| | | * @Param: [date] |
| | | * @return: boolean |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/23 |
| | | */ |
| | | public static boolean checkDate(String date){ |
| | | String regex = "((\\d{2}(([02468][048])|([13579][26]))[\\-]((((0?[13578])|(1[02]))[\\-]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-]((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-]((((0?[13578])|(1[02]))[\\-]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-]((0?[1-9])|(1[0-9])|(2[0-8]))))))"; |
| | | return Pattern.matches(regex,date); |
| | | } |
| | | |
| | | /** |
| | | * 验证URL地址 |
| | | * |
| | | * @param url 格式:http://blog.csdn.net:80/xyang81/article/details/7705960? 或 http://www.csdn.net:80 |
| | |
| | | return Pattern.matches(regex, ipAddress); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 判断字符串是否包含中文 |
| | | * @Param: [str] |
| | | * @return: boolean |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/21 |
| | | */ |
| | | public static boolean checkContainChinese(String str){ |
| | | Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); |
| | | Matcher matcher = p.matcher(str); |
| | | return matcher.find(); |
| | | } |
| | | |
| | | } |