当前位置:网站首页>常见的正则表达式
常见的正则表达式
2022-04-23 06:09:00 【dotphoenix】
package com.modules.plateform.tool; import java.util.regex.Pattern; /** * 账户相关属性验证工具 * */ public class AccountValidatorUtil { /** * 正则表达式:验证用户名 */ public static final String REGEX_USERNAME = "^[a-zA-Z]\\w{5,20}$"; /** * 正则表达式:验证密码 */ public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]{6,20}$"; /** * 正则表达式:验证手机号 */ public static final String REGEX_MOBILE = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"; /** * 正则表达式:验证邮箱 */ public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; /** * 正则表达式:验证汉字 */ public static final String REGEX_CHINESE = "^[\u4e00-\u9fa5],{0,}$"; /** * 正则表达式:验证身份证 */ public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)"; /** * 正则表达式:验证URL */ public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"; /** * 正则表达式:验证IP地址 */ public static final String REGEX_IP_ADDR = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)"; /** * 校验用户名 * * @param username * @return 校验通过返回true,否则返回false */ public static boolean isUsername(String username) { return Pattern.matches(REGEX_USERNAME, username); } /** * 校验密码 * * @param password * @return 校验通过返回true,否则返回false */ public static boolean isPassword(String password) { return Pattern.matches(REGEX_PASSWORD, password); } /** * 校验手机号 * * @param mobile * @return 校验通过返回true,否则返回false */ public static boolean isMobile(String mobile) { return Pattern.matches(REGEX_MOBILE, mobile); } /** * 校验邮箱 * * @param email * @return 校验通过返回true,否则返回false */ public static boolean isEmail(String email) { return Pattern.matches(REGEX_EMAIL, email); } /** * 校验汉字 * * @param chinese * @return 校验通过返回true,否则返回false */ public static boolean isChinese(String chinese) { return Pattern.matches(REGEX_CHINESE, chinese); } /** * 校验身份证 * * @param idCard * @return 校验通过返回true,否则返回false */ public static boolean isIDCard(String idCard) { return Pattern.matches(REGEX_ID_CARD, idCard); } /** * 校验URL * * @param url * @return 校验通过返回true,否则返回false */ public static boolean isUrl(String url) { return Pattern.matches(REGEX_URL, url); } /** * 校验IP地址 * * @param ipAddr * @return */ public static boolean isIPAddr(String ipAddr) { return Pattern.matches(REGEX_IP_ADDR, ipAddr); } }
版权声明
本文为[dotphoenix]所创,转载请带上原文链接,感谢
https://blog.csdn.net/dotphoenix/article/details/102089045
边栏推荐
- MarkDown基础语法笔记
- 【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
- oracle对表字段的修改
- 组件化学习(3)ARouter中的Path和Group注解
- 一款png生成webp,gif, apng,同时支持webp,gif, apng转化的工具iSparta
- oracle杀死正在执行的sql
- Itop4412 HDMI display (4.4.4_r1)
- 专用窗口函数rank, dense_rank, row_number
- this.getOptions is not a function
- useReducer基本用法
猜你喜欢
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
组件化学习(3)ARouter中的Path和Group注解
Android清除应用缓存
webView因证书问题显示一片空白
一款png生成webp,gif, apng,同时支持webp,gif, apng转化的工具iSparta
Itop4412 LCD backlight drive (PWM)
Explore how @ modelandview can forward data and pages through the source code
Cause: dx.jar is missing
【2021年新书推荐】Professional Azure SQL Managed Database Administration
【2021年新书推荐】Learn WinUI 3.0
随机推荐
同时解决高度塌陷和外边距重叠问题
mysql和pgsql时间相关操作
Markdown basic grammar notes
开篇:双指针仪表盘的识别
组件化学习(1)思想及实现方式
adb shell常用模拟按键keycode
Component learning (2) arouter principle learning
补补网络缺口
iTOP4412 SurfaceFlinger(4.0.3_r1)
Component based learning (1) idea and Implementation
oracle 修改默认临时表空间
iTOP4412无法显示开机动画(4.0.3_r1)
SQL中 with函数的详解与用法
[SM8150][Pixel4]LCD驱动
Exception record-9
Abnormal record-22
oracle表空间表分区详解及oracle表分区查询使用方法
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation
Handler进阶之sendMessage原理探索
Component based learning (3) path and group annotations in arouter