Android : Validate half-width Japanese character
I've created method validates if typed character is half-width kana
:
public boolean validate(String c) {
Pattern pattern = Pattern.compile("[\uff61-\uff9f]");
return pattern.matcher(c).matches();
}
I understood that you want to check is written text composed of only half-width kana, yes? To do this, in onClick()
of button which you clicking for validate, write something like this:
for (int i = 0; i < textToValidate.length(); i++) {
if (validate(textToValidate.charAt(i))) {
continue;
} else {
System.out.println("Text wasn't written in half-width kana.");
return;
}
}
System.out.println("Text was written in half-width kana.");
Let me know if my answer is helpful for you. ;)