Java ASCII文字列かの判定
ASCII文字のみから構成されるか確認
if (str.matches("\\p{ASCII}*")) {
System.out.println("Ascii charcter only.");
}
ASCII文字以外が含まれているか確認
if (str.matches("^.*[^\\p{ASCII}].*")) {
System.out.println("Not Ascii charcter conatins.");
}
if (str.matches("\\p{ASCII}*")) {
System.out.println("Ascii charcter only.");
}
if (str.matches("^.*[^\\p{ASCII}].*")) {
System.out.println("Not Ascii charcter conatins.");
}
YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto
Copyright© 矢木 浩人 All Rights Reserved.