常用正则匹配表达式

前端之家收集整理的这篇文章主要介绍了常用正则匹配表达式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. public class RegExpUtil {
  2. private static final String IS_NUMBER ="^[0-9]+$";
  3. private static final String IS_USERNAME = "^[a-zA-Z]\\w{5,17}$";
  4. private static final String IS_PASSWORD = "^[a-zA-Z][\\w]{5,17}$";
  5. private static final String IS_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
  6. private static final String IS_URL = "^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
  7. private static final String IS_MOBILE_PHONE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"; //移动电话 手机
  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})$"; //固定电话
  9. private static final String IS_CHINESE = "[\u4e00-\u9fa5]";
  10. public static boolean isNumber(String str){
  11. Pattern p = Pattern.compile(IS_NUMBER);
  12. return p.matcher(str).matches();
  13. }
  14. public static boolean isUserName(String str){
  15. Pattern p = Pattern.compile(IS_USERNAME);
  16. return p.matcher(str).matches();
  17. }
  18. public static boolean isPassword(String str){
  19. Pattern p = Pattern.compile(IS_PASSWORD);
  20. return p.matcher(str).matches();
  21. }
  22. public static boolean isEmail(String str){
  23. Pattern p = Pattern.compile(IS_EMAIL);
  24. return p.matcher(str).matches();
  25. }
  26. public static boolean isURL(String str){
  27. Pattern p = Pattern.compile(IS_URL);
  28. return p.matcher(str).matches();
  29. }
  30. public static boolean isMobilePhone(String str){
  31. Pattern p = Pattern.compile(IS_MOBILE_PHONE);
  32. return p.matcher(str).matches();
  33. }
  34. public static boolean isPhone(String str){
  35. Pattern p = Pattern.compile(IS_PHONE);
  36. return p.matcher(str).matches();
  37. }
  38. public static boolean isChinese(String str){
  39. Pattern p = Pattern.compile(IS_CHINESE);
  40. return p.matcher(str).matches();
  41. }
  42. public static boolean isContainBlank(String str){
  43. return str.indexOf(" ")>-1?true:false;
  44. }
  45. }

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