文字列の検証

  • 全角文字判定


protected static boolean isFullString(String s) {

Pattern pattern = Pattern.compile("^[^ -~。-゚]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • 半角英字判定


protected static boolean isHalfAl(String s) {

Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • 半角数字判定


protected static boolean isHalNum(String s) {

Pattern pattern = Pattern.compile("^[0-9]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • 半角英数字判定


protected static boolean isHalfAlNum(String s) {

Pattern pattern = Pattern.compile("^[a-zA-Z0-9]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • 半角英数記号判定


protected static boolean isAlNumSign(String s) {

Pattern pattern = Pattern.compile("^[a-zA-Z0-9 -/:-@\[-\`\{-\~]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • 半角カタカナ判定


protected static boolean isHalfKana(String s) {

Pattern pattern = Pattern.compile("^[。-゚+]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • ひらがな判定


protected static boolean isHiragana(String s) {

Pattern pattern = Pattern.compile("^[ぁ-ゞ]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}



  • 全角カタカナ判定

protected static boolean isFullKana(String s) {

Pattern pattern = Pattern.compile("^[ァ-ヶ]+$");
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}

0 コメント: