Java正则表达式验证至少6位表达式中至少包含数字大小写字母中的一种
直接上代码
public class TestRegex { public static void main(String[] args){ String a = "^(?!^$)([a-zA-Z0-9]{6,})$"; Pattern pattern2 = Pattern.compile(a); System.out.println("1111111:"+pattern2.matcher("1111111").matches()); System.out.println("aaaaaaa:"+pattern2.matcher("aaaaaaa").matches()); System.out.println("AAAAAAA:"+pattern2.matcher("AAAAAAA").matches()); System.out.println("1111AAA:"+pattern2.matcher("1111AAA").matches()); System.out.println("1111aaq:"+pattern2.matcher("1111aaq").matches()); System.out.println("1111Aaq:"+pattern2.matcher("1111Aaq").matches()); System.out.println("1111Aa!:"+pattern2.matcher("1111Aa!").matches()); } }
执行结果