Jason Kim
Jason Kim

Reputation: 19051

Korean regex check: How to allow only full letter (e.g. 회원이름) and guard against none letters (e.g. ㅋㅋㅋ)

Is there a Ruby or Rails way to make sure usernames in Korean are composed of full letters like 회원이름 rather than just consonants or vowels like ㅋㅋㅋ or ㅏㅏㅏ ?

If Ruby or Rails way is not available, how would you write a method to validate this condition?

Upvotes: 2

Views: 587

Answers (1)

Alex D
Alex D

Reputation: 30455

I don't know Korean, but I have written Ruby code to work with Chinese text before. (If you are interested, I can provide a GitHub link.)

When I was writing that code, I looked at the Unicode standard (see http://unicode.org/charts) and found which ranges of codepoints represent Chinese characters. I made sure that all the strings in my scripts were encoded as UTF-8, and then used:

str.codepoints

...To get a sequence of Unicode codepoints (as integers). Then I could go through that sequence of integers and find all the Chinese characters.

In your case, if you look up the Unicode codepoints for Korean characters, I'm sure you can do the same. I can see Hangul Jamo, Hangul Syllables, etc. in the Unicode charts, but I'm not sure which one of these is the one you want.

You should also think carefully about which other characters you want to allow/disallow -- for example, is is OK if your users mix ASCII text, punctuation, Chinese, Japanese, Arabic, etc. with Hangul?

Upvotes: 1

Related Questions