i"m trying to fint if a string starts(first letter) width an RTL language/ hebrew.
any ideas?
i"m trying to fint if a string starts(first letter) width an RTL language/ hebrew.
any ideas?
This will find hebrew letters encoded in the Hebrew Unicode code point range: [\u0590-\u05FF]
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
// 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;
}
if (str.charCodeAt(0) >= 0x590) && (str.charCodeAt(0) <= 0x5FF) then
it is considered a hebrew character
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 ]