我有一个多语种的网站,我想限制使用正则表达式输入其他语言字符(特别是中文)。谁能给我举个例子来实现这一点吗?
小提琴:
$(".textTest input").keyup(function () { if ($(this).val().match(/^[\u4E00-\u9FFF\u3400-\u4DFF\uF900-\uFAFF]+$/g)) { alert('Chinese character sets'); } else alert('English'); });
http://jsfiddle.net/srikanth1818/ofkhsr9x/
发布于 2014-12-30 12:56:36
你正朝着正确的方向前进。下面的代码检查Unicode中的汉字集。
$(".textTest input").keyup(function () {
if ($(this).val().match(/[\u4E00-\u9FFF\u3400-\u4DFF\uF900-\uFAFF]+/g)) {
alert('Chinese character sets');
}
else alert('English');
});更多信息可以在这里找到:
What's the complete range for Chinese characters in Unicode?
https://stackoverflow.com/questions/27704708
复制相似问题