文字列が(最初の文字の)幅でRTL言語/ヘブライ語で始まるかどうかを調べようとしています。
何か案は?
これにより、ヘブライ語Unicodeコードポイント範囲でエンコードされたヘブライ文字が見つかります。[\u0590-\u05FF]
\p{InHebrew}
JavaScriptは、 (または同様のもの)のような正規表現スクリプトをサポートしていません。ただし、Unicodeエスケープをサポートしているため、次のような正規表現を使用できます。
/[\u0590-\u05FF]/
これは、単一のヘブライ文字に一致します。
参照: http: //unicode.org/charts/PDF/U0590.pdf および: http: //www.regular-expressions.info/unicode.html
function is_heb(Field) {
// 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;
} else
return true;
}
<input id="the_text" type="text" value="בדיקה" />
<br /><button onclick="document.getElementById('the_result').value = is_heb(document.getElementById('the_text').value)">Is it Hebrew?</button>
<br /><br />
Result:
<br /><input id="the_result" type="text">
if (str.charCodeAt(0) >= 0x590) && (str.charCodeAt(0) <= 0x5FF) then
ヘブライ文字と見なされます
特にヘブライ語の場合、質問はすでに回答されています-すべての範囲に関して:
特にJSの場合は、正規表現を作成するためのツールをお勧めします。Unicode範囲のRegExpジェネレーターを参照してください(JavaScriptでの使用に適した文字範囲をコンパイルします)
[ヘブライ語または必要なスクリプトまたは範囲を選択するだけです]