Javascript - how to find hebrew?

橙三吉。 提交于 2019-11-26 18:13:35

问题


i"m trying to fint if a string starts(first letter) width an RTL language/ hebrew.

any ideas?


回答1:


This will find hebrew letters encoded in the Hebrew Unicode code point range: [\u0590-\u05FF]




回答2:


JavaScript does not support regex scripts like \p{InHebrew} (or something similar). However, it does support Unicode escapes, so you could use a regex like:

/[\u0590-\u05FF]/

which will match a single Hebrew character.

See: http://unicode.org/charts/PDF/U0590.pdf and: http://www.regular-expressions.info/unicode.html




回答3:


// First choose the required validation

HebrewChars = new RegExp("^[\u0590-\u05FF]+$");
AlphaNumericChars = new RegExp("^[a-zA-Z0-9\-]+$");
EnglishChars = new RegExp("^[a-zA-Z\-]+$");
LegalChars = new RegExp("^[a-zA-Z\-\u0590-\u05FF ]+$"); //Note that this one allows space 

// Then use it

if (!LegalChars.test(Field)) {
    return false;
}



回答4:


if (str.charCodeAt(0) >= 0x590) && (str.charCodeAt(0) <= 0x5FF) then it is considered a hebrew character




回答5:


Especially for Hebrew the question is answered already - regarding all ranges:

Especially for JS I would recommend a tool to build your regex - see Unicode range RegExp generator (Compiles character ranges suitable for use in JavaScript)

[ just select hebrew or the scripts or ranges you want ]



来源:https://stackoverflow.com/questions/2041859/javascript-how-to-find-hebrew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!