最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android常用正则表达式验证工具类(实例代码)
时间:2022-06-29 01:08:37 编辑:袖梨 来源:一聚教程网
东西不多,但一般项目够用了。
public class RegularUtil {
//身份证
public static final String REGEX_ID_CARD = "^[1-9]d{5}[1-9]d{3}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}([0-9]|X)$";
//验证邮箱
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_PHONE = "0?(13|14|15|17|18)[0-9]{9}";
//汉字
public static final String REGEX_TRUENAME = "^[u4e00-u9fa5]*$";
//银行卡
public static final String BANKNUMBER="^([0-9]{16}|[0-9]{19})$";
//固话电话正则
public static final String TELE= "([0-9]{3,4}-)?[0-9]{7,8}";
//密码强度验证
public static final String REGEX_PWS="^(((?=.*[0-9])(?=.*[a-zA-Z])|(?=.*[0-9])(?=.*[^s0-9a-zA-Z])|(?=.*[a-zA-Z])(?=.*[^s0-9a-zA-Z]))[^s]+)$";
public static boolean isPhone(String mobiles){
if (TextUtils.isEmpty(mobiles)){
return false;
}else{
return mobiles.matches(REGEX_PHONE);
}
}
public static boolean isTel(String mobiles) {
if (TextUtils.isEmpty(mobiles)) {
return false;
} else {
return mobiles.matches(TELE);
}
}
public static boolean isIDacard(String idcard){
if (TextUtils.isEmpty(idcard))
return false;
else
return idcard.matches(REGEX_ID_CARD);
}
public static boolean isBankCard(String bankcard){
if (TextUtils.isEmpty(bankcard))
return false;
else
return bankcard.matches(BANKNUMBER);
}
public static boolean isEmail(String email){
if (TextUtils.isEmpty(email))
return false;
else
return email.matches(REGEX_EMAIL);
}
public static boolean isTrueName(String name){
if (TextUtils.isEmpty(name))
return false;
else
return name.matches(REGEX_TRUENAME);
}
//验证密码强度
public static boolean isPsw(String psw) {
//包含数字,字母,特殊符号其中至少两种
if (TextUtils.isEmpty(psw)) {
return false;
} else {
//限制长度
if(psw.length()<6||psw.length()>16){
return false;
}
//matches():字符串是否在给定的正则表达式匹配
return psw.matches(REGEX_PWS);
}
}
}
相关文章
- 差差漫画登录首页-差差漫画在线登录免费弹窗 02-06
- 抖音网页版入口-官方电脑版登录免费教程2026 02-06
- 差差漫画官方最新版本下载安装入口-差差漫画免费高清漫画页面在线观看 02-06
- 百度地图如何打开全景模式-百度地图全景开启方法 02-06
- poki游戏官网正版入口-poki游戏正版安全无忧官网 02-06
- picacg游咔-官网最新入口2026 02-06