javascript - How to use regex for some specific country character? -
i validating username using regex in js. however, giving me error other country character. found regex other country character.
if(/^[a-za-z0-9äöüÄÖÜß\u4e00-\u9faf\u3040-\u3096\u30a1-\u30fa\uff66-\uff9d\u31f0-\u31ff\x30a0-\x30ffñáéíóúü\p{han}\u1100-\u11ff|\u3130-\u318f|\ua960-\ua97f|\uac00-\ud7af|\ud7b0-\ud7ffàâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ\u00c0-\u017f\u4e00-\u9fff|\u2ff0-\u2fff|\u31c0-\u31ef|\u3200-\u9fbf|\uf900-\ufaffzàèéìòóù\u00e0\u00e8\u00e9\u00ec\u00f2\u00f3\u00f9._-]{1,160}$/i.test(text)){ console.log('correct word'); } else { console.log('wrong word'); }
but want allow specific country e.g
korean: hangul, chosŏn'gŭl japanese: hiragana, katakana (full width), kanji german spanish french italian chinese: simplified chinese russian portuguese.
i want can manually remove country character, e.g want remove "simplified chinese", don't can in code because don't know string used country character in if condition. please help?
i not familiar of languages have mentioned can tell how can create regex language.
there simple method apply regex logic(that 1 can apply in english) language using unicode.
for matching range of unicode characters alphabets [a-za-z] can use
[\u0041-\u005a] \u0041 hex-code , \u005a hex code z 'matchcaps letter'.match(/[\u0041-\u005a]+/g) //output ["caps", "tt"] 'matchcaps letter'.match(/[a-z]+/g) //output ["caps", "tt"]
in same way can use other unicode characters or equivalent hex-code according hexadecimal order (eg: \u0a10 \u0a1f) provided unicode.org
try: [电-触] chinese
it match characters between 电 , 触 if provided unicode.org in order
similarly can add characters other languages in 1 regex as
/[电-触ڀ-ڴᄀ-ᆿ]/ //combination of chinese, arabic, korean
note:
make sure using correct range alphabets
Comments
Post a Comment