前端之家收集整理的这篇文章主要介绍了
常用正则匹配表达式,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- public class RegExpUtil {
- private static final String IS_NUMBER ="^[0-9]+$";
- private static final String IS_USERNAME = "^[a-zA-Z]\\w{5,17}$";
- private static final String IS_PASSWORD = "^[a-zA-Z][\\w]{5,17}$";
- private static final String IS_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
- private static final String IS_URL = "^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
- private static final String IS_MOBILE_PHONE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"; //移动电话 手机
- private static final String IS_PHONE = "^(((\\d{3,4}-)|(\\d{3,4}-)?)\\d{7,8})|([0-9]{3}-[0-9]{3}-[0-9]{4})$"; //固定电话
- private static final String IS_CHINESE = "[\u4e00-\u9fa5]";
-
-
- public static boolean isNumber(String str){
- Pattern p = Pattern.compile(IS_NUMBER);
- return p.matcher(str).matches();
- }
- public static boolean isUserName(String str){
- Pattern p = Pattern.compile(IS_USERNAME);
- return p.matcher(str).matches();
- }
- public static boolean isPassword(String str){
- Pattern p = Pattern.compile(IS_PASSWORD);
- return p.matcher(str).matches();
- }
- public static boolean isEmail(String str){
- Pattern p = Pattern.compile(IS_EMAIL);
- return p.matcher(str).matches();
- }
- public static boolean isURL(String str){
- Pattern p = Pattern.compile(IS_URL);
- return p.matcher(str).matches();
- }
- public static boolean isMobilePhone(String str){
- Pattern p = Pattern.compile(IS_MOBILE_PHONE);
- return p.matcher(str).matches();
- }
- public static boolean isPhone(String str){
- Pattern p = Pattern.compile(IS_PHONE);
- return p.matcher(str).matches();
- }
- public static boolean isChinese(String str){
- Pattern p = Pattern.compile(IS_CHINESE);
- return p.matcher(str).matches();
- }
-
- public static boolean isContainBlank(String str){
- return str.indexOf(" ")>-1?true:false;
- }
- }