Javascript - how to find hebrew?

2019-01-11 04:03发布

问题:

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 ]