String name = "zhangsan";
System.out.println(name.matches("^[A-Za-z]{2,4}+$"));//只能是字母
name = "张三HXa12121";
System.out.println(name.matches("^[A-Za-z\u4e00-\u9fa5]+$"));//只能是汉字加拼音
name = "张三张三";
System.out.println(name.matches("^[\u4e00-\u9fa5]{2,4}+$"));//只能是汉字
System.out.println(name.matches("^[A-Za-z]{2,4}+$"));//只能是字母
name = "张三HXa12121";
System.out.println(name.matches("^[A-Za-z\u4e00-\u9fa5]+$"));//只能是汉字加拼音
name = "张三张三";
System.out.println(name.matches("^[\u4e00-\u9fa5]{2,4}+$"));//只能是汉字