加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

常用的正则表达式,拿走不客气

发布时间:2020-12-14 00:40:39 所属栏目:百科 来源:网络整理
导读:很多都是项目中正在使用的,自己抽空梳理了一下,有补充的后续再补上。 检验手机号 String regex = "^((13[0-9])|(15[^4,D])|(18[0,0-9]))d{8}$" ; if (str == null || "" .equals(str.trim())) { return false ;} else if (str.matches(regex)) { retur

很多都是项目中正在使用的,自己抽空梳理了一下,有补充的后续再补上。

检验手机号

String regex = "^((13[0-9])|(15[^4,D])|(18[0,0-9]))d{8}$";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

检验身份证号

String regex = "(^d{14}[0-9|xX]$)|(^d{17}[0-9|xX]$)";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

校验密码强度

String regex = "^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

校验中文

String regex = "^[u4e00-u9fa5]{0,}$";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

校验由数字,26个英文字母或下划线组成的字符串

String regex = "^w+$";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

校验E-Mail 地址

String regex = "[w!#$%&'*+/=?^_`{|}~-]+(?:.[w!#$%&'*+/=?^_`{|}~-]+)*@(?:[w](?:[w-]*[w])?.)+[w](?:[w-]*[w])?";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

校验日期

String regex = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

校验金额

String regex = "^[0-9]+(.[0-9]{2})?$";
if (str == null || "".equals(str.trim())) {
    return false;
} else if (str.matches(regex)) {
    return true;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读