I wanted code to accept all 7 bit ascii character set but not to accept 8bit characters. I have tried with regular expression:
user.getFirstName()).matches("[\\w\\s]+")
I wanted code to accept all 7 bit ascii character set but not to accept 8bit characters. I have tried with regular expression:
user.getFirstName()).matches("[\\w\\s]+")
There is a Java Regular Expressions class for this set. It is \p{ASCII}
. See Pattern class.
"ABC".matches("\\p{ASCII}+") == true;
"ABCŻ".matches("\\p{ASCII}+") == false;
There is the '\x' way of entering numbers hexadecimally: (Source http://www.regular-expressions.info/reference.html )
yourString.matches("[\\x00-\\x7F]+");
In Java this might be:
yourString.matches("[\\u0000-\\u007F]+");