我希望代码接受所有7位ascii字符集但不接受8位字符。我试过正则表达式:
user.getFirstName()).matches("[\\w\\s]+")
答案 0 :(得分:4)
此集合有一个Java正则表达式类。它是\p{ASCII}
。见Pattern class。
"ABC".matches("\\p{ASCII}+") == true;
"ABCŻ".matches("\\p{ASCII}+") == false;
答案 1 :(得分:3)
以十六进制方式输入数字的'\ x'方式:(来源http://www.regular-expressions.info/reference.html)
yourString.matches("[\\x00-\\x7F]+");
在Java中,这可能是:
yourString.matches("[\\u0000-\\u007F]+");