在stackoverflow看到簡單的正規表示式解法,可驗證任一非數字或字母的字元。
String userIDNotLogin= "未登入";
String userIDLogin = "U12345";
Pattern notAlphanumeric = Pattern.compile("[^a-zA-Z0-9]");
notAlphanumeric.matcher(userIDNotLogin).find(); → True
notAlphanumeric.matcher(userIDLogin ).find(); → False