This question might have been asked several times but I didn't find a proper answer so I am posting this question. What I want to do is validate the Japanese text entered in the edit text field to allow only half-width Japanese characters. I only want to check the validation once user enters the text and taps on some action button.
To convert a string into half-width Katakana characters, press [F9].
Half-width refers to characters where the horizontal and vertical length ratio is 1:2. These characters are horizontally narrow. English letters, numbers, spaces, and punctuation marks such as comma and period are half-width by default.
For Windows: Use F10 within an online form to toggle quickly between full-width and half-width characters. For Mac users: Full-width, zenkaku katakana, is control + k.
Adjective. fullwidth (not comparable) (computing, typography) Of a text character, occupying the space of two alphanumeric characters in a monospace font, or two "normal" text columns.
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. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With