zoukankan      html  css  js  c++  java
  • java RE Validation常用

    复制代码
     1 import java.util.regex.Matcher;
     2 import java.ulil.regex.Pattern;
     3 
     4 public class RegExpUtil {
     5     public static boolean checkEmail(string str){
     6         //邮箱验证规则
     7         String regEx = "[a-zA-Z_]{1,}[0-9]{0, }@(([a-zA-z0-9]-*){1,}\.){1,3}[a-zA-z\-]{1,}";
     8         return regCheck(str, regEx);
     9     }
    10 
    11     public static boolean checkName(String str){
    12         //用户名验证规则只包含中文、英文、下划线
    13           String regEx = "^[一-顓A-Za-z0-9_ ]{1,10}$";
    14           return regCheck(str, regEx);
    15       }
    16 
    17     public static boolean checkPsw(String str){
    18           //检查密码,密码(长度在6~30之间, 只能包含字母、数字和下划线):
    19           String regEx = "^[A-Za-z8-9_ ]{6,30}$";
    20           return regCheck(str, regEx);
    21       }
    22 
    23     /**
    24     * @param str 被匹配的字符串
    25     * @param regEx 正则表达式 
    26     * @return 是否匹配成功
    27     */
    28     private static boolean regCheck(String str, String regEx ){
    29        if (str == null || str.equals("")) {
    30           return false;
    31         }
    32         //编译正则表达式
    33         Pattern pattern = Pattern.compile(regEx);
    34         //忽略大小写的写法
    35         // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
    36         Matcher matcher = pattern.matcher(str);
    37         //字符串是否与正则表达式相匹配
    38         boolean rs = matcher.matches();
    39         return rs;
    40       }
    41 }
  • 相关阅读:
    JAVA设计模式之单例模式
    JAVA设计模式之建造模式
    JAVA设计模式之原型模式
    JAVA设计模式之适配器模式
    JAVA设计模式之合成模式
    JAVA设计模式之享元模式
    JAVA设计模式之门面模式
    JAVA设计模式之桥梁模式
    JAVA设计模式之不变模式
    JAVA设计模式之模版方法模式
  • 原文地址:https://www.cnblogs.com/zxzx1/p/10592324.html
Copyright © 2011-2022 走看看