常用正则匹配表达式
发布时间:2020-12-14 04:37:28 所属栏目:百科 来源:网络整理
导读: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_EMA
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; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |