A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© funny 中级黑马   /  2015-9-9 23:16  /  499 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.wf.dao;

public class Test1 {

        /**
         *
                1,1-6位字母或数字:
                2,手机号
                3,Email
                4,用户名. 字母数字下划线10位以内, 必须是字母开头
                5,密码. 任意字符, 6-16位
                6,分组,例如快快乐乐,乐呵乐呵
                7,手机号码,后边五位必须是相同的
         */
        public static void main(String[] args) {
//                demo1();
//                demo2();
//                demo3();
                demo4();
//                demo5();
//                demo6();
//                demo7();
//                demo8();
        }

        private static void demo8() {
                String regex1 = "1[34578]\\d{9}";
                String regex2 = "1[34578]\\d{4}(\\d)\\1{4}";
                System.out.println("13812300000".matches(regex2));
                System.out.println("15932166666".matches(regex2));
                System.out.println("13812345678".matches(regex2));
        }

        public static void demo7() {
                String regex = "(.)\\1+(.)\\2+";
                System.out.println("快快乐乐".matches(regex));
                System.out.println("高高兴兴".matches(regex));
                System.out.println("快快快乐乐乐".matches(regex));
               
                String regex2 = "(..)\\1";
                System.out.println("乐呵乐呵".matches(regex2));
                System.out.println("死啦死啦".matches(regex2));
        }

        public static void demo6() {
                //5,密码. 任意字符, 6-16位
                String regex = ".{6,16}";
                System.out.println("123456".matches(regex));
                System.out.println("abcde".matches(regex));
                System.out.println("1234567890987654".matches(regex));
                System.out.println("12345678909876543".matches(regex));
        }

        public static void demo5() {
                //4,用户名. 字母数字下划线10位以内, 必须是字母开头
                String regex = "[a-zA-Z]\\w{0,9}";
                System.out.println("0abcde".matches(regex));
                System.out.println("a".matches(regex));
                System.out.println("abcdef12345".matches(regex));
        }

        public static void demo4() {
                //3,Email   fengjia@itcast.cn
                //          fengjia@itcast.com.cn
                String regex = "[\\w-\\.]+@([\\w-]+\\.)+[a-z]{2,3}";
                System.out.println("fengjia@itcast.cn".matches(regex));
                System.out.println("2553868@qq.com".matches(regex));
                System.out.println("fengjia@itcast.cn".matches(regex));
        }

        public static void demo3() {
                //2,手机号
                String regex = "1[34578]\\d{9}";
                System.out.println("13898765432".matches(regex));
                System.out.println("01234567890".matches(regex));
                System.out.println("16123456789".matches(regex));
                System.out.println("159123456780".matches(regex));
        }

        public static void demo2() {
                //1,1-6位字母或数字:
                String regex = "[\\d[a-zA-Z]]{1,6}";
                System.out.println("123456".matches(regex));
                System.out.println("1".matches(regex));
                System.out.println("abcd".matches(regex));
        }

        public static void demo1() {
                //qq号码
                String regex = "[1-9]\\d{4,10}";
                System.out.println("2553868".matches(regex));
                System.out.println("012345".matches(regex));
                System.out.println("12345678987".matches(regex));
        }

}

1 个回复

倒序浏览
谢谢分享,赞一个!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马