java 正则表达式

来源:互联网 发布:慕思城的淘宝视频 编辑:程序博客网 时间:2024/06/11 05:49

转: http://www.maxiaoguo.com/foods/362.html

1、要求4-10个中英文 数字或者 下划线

 /**

     * 验证昵称
     * @param code

     * @return  

     */
    public static boolean regiestNickCode(String code){
   
    String regiex = "[\u4e00-\u9fa50-9a-zA-Z_]{4,10}";
    Pattern pattern = Pattern.compile(regiex);
    Matcher matcher = pattern.matcher(code);
    boolean b= matcher.matches();
    return b;
    }

    

2、要求 支持6-20个 数字 字母 下划线 减号 需要以字母开头

    /**
     * 验证昵称
     * @param code
     * @return
     */
    public static boolean regiestUserName(String code){
   
    String regiex = "[a-zA-Z]{1}[a-zA-Z0-9_-]{5,20}";
    Pattern pattern = Pattern.compile(regiex);
    Matcher matcher = pattern.matcher(code);
    boolean b= matcher.matches();
    return b;

    }



原创粉丝点击