EDIT: Thanks to GOTO 0
, I now know exactly what I my question is called.
I need a JavaScript function to convert from UTF-8 fullwidth form to halfwidth form.
EDIT: Thanks to GOTO 0
, I now know exactly what I my question is called.
I need a JavaScript function to convert from UTF-8 fullwidth form to halfwidth form.
Apperently, you want to convert halfwidth and fullwidth form characters to their equivalent basic latin forms. If this is correct, you can do a replacement using a regular expression. Something like this should work:
Where x is your input string and y is the output.
Year 2018 answer
Many years later – and it’s still impossible to find on the Internet a function that does this. So I wrote mine. (Nearly learned Japanese and Korean to get to this point.)
Simple version
Latin range only.
Complete version
Let me know if I missed any character.
The answer of GOTO 0 is very useful, but I also need convert space from fullwidth to halfwidth.
So below is my code:
The given solutions do not work for all the cases of Full-Width to Half-Width conversion of Kana (eg. デジタル is not converted properly). I have made a function for converting Zenkaku to Hankaku Katakana, Hope it helps.
Use as follows
convertToHalfWidth('デジタル');
You can pass the result of this function to the function mentioned by
GOTO 0
and get the complete Half width result for the Japanese LanguageReference: https://en.wikipedia.org/wiki/Katakana#Unicode
Try this