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

前端之家收集整理的这篇文章主要介绍了常用的正则表达式,拿走不客气前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

检验手机号

@H_502_9@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; }

检验身份证号

@H_502_9@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; }

校验密码强度

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

校验中文

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

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

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

校验E-Mail 地址

@H_502_9@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; }

校验日期

@H_502_9@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; }

校验金额

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

猜你在找的正则表达式相关文章