在 JavaScript 正则表达式中包含阿拉伯字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12847333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:15:23 来源:igfitidea点击:
Include Arabic characters in JavaScript regular expression?
提问by Josh Fradley
So im using jquery validation on my script to only allows certain characters. I've had a request to allow the script to use arabic characters aswell. How would i do this?
所以我在我的脚本上使用 jquery 验证只允许某些字符。我曾请求允许脚本也使用阿拉伯字符。我该怎么做?
Heres my current code:
继承人我目前的代码:
$.validator.addMethod(
"legalname",
function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9()._\-\s]+$/.test(value);
},
"Illegal character. Only points, spaces, underscores or dashes are allowed."
);
回答by Mohsen Afshin
回答by Anton Baksheiev
Try this:
试试这个:
function HasArabicCharacters(text)
{
var arregex = /[\u0600-\u06FF]/;
alert(arregex.test(text));
}
For more info take a look here Arabic Unicode block
有关更多信息,请查看此处的阿拉伯语 Unicode 块