貌似正则表达式有问题,应该是^[^ ]{6,16}$
String reg = "^[^\\s]{6,16}$";String str = "abcd12";if (str.matches(reg)) { ...} else { ...}