正则 只有英文或者数字 长度6位以上 数字或者英文全部一样

要求 

1 只有英文或者数字

2 长度大于6位

3 不能全部是相同的数字或字母

解决:

自己写了一个测试类

public class emailTest {
    public static void main(String[] args) {

     for(int i =0;i<10;i++){
         Scanner scanner = new Scanner(System.in);

         //annotate 注解
         System.out.println("请输入oe");
         String account = scanner.nextLine();
         String regex1 = "^[a-zA-Z0-9]{6,}$";
         String regex2 = "^([0-9a-zA-Z])\1+$";
         Pattern  pattern = Pattern.compile(regex1);
         Matcher  matcher = pattern.matcher(account);
         Pattern  pattern1 = Pattern.compile(regex2);
         Matcher  matcher1 = pattern1.matcher(account);


         if (matcher1.matches()||!matcher.matches()) {
             System.out.println("oe码不能为中文字符,长度大于等于6位,不能全部是相同的数字或字母");
         } else {
             System.out.println("正确");
         }

     }

    }
}

输出:

原文地址:https://www.cnblogs.com/zq1003/p/14098803.html