Here are several solutions that might work for various requirements:
Text must have no ASCII-only letters
if (text.matches("\\P{Alpha}+")) {
System.out.println("No ASCII letters");
}
Text must have no letter from the whole BMP plane
if (text.matches("\\P{L}+")) {
System.out.println("No Unicode letters");
}
Text must have no alphabetic chars
if (text.matches("\\P{IsAlphabetic}+")) {
System.out.println("No alphabetic chars");
}
*Note: the IsAlphabetic
class includes L
, Nl
(Letter number) and Other_Alphabetic
categories and might be too broad, but is good if you need to check for letters and diacritics.
The String#matches
method requires a full string match, hence no anchors (^
/\A
and $
/\z
) are used in the above code snippets.