我需要用什么正则表达式来检查一些非拉丁字符? [英] What regular expression do I need to check for some non-latin characters?

查看:184
本文介绍了我需要用什么正则表达式来检查一些非拉丁字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果字段是拉丁字符,我正在检查字段。

I am checking a field if it is Latin Characters or not.

var foreignCharacters = $("#foreign_characters").val();
var rlatins = /[\u0000-\u007f]/;

if (rlatins.test(foreignCharacters)) {
  alert("This is Latin Characters");
} else {
  alert("This is non-latin Characters");    
}

这很有效,但我想改变它,所以当我输入任何非拉丁字符,例如中文字符,以及空格(在我目前使用的范围内),它仍然会说它是非拉丁字符。

This works well, but I would like to change it so when I enter any non-latin characters, such as chinese characters, along with a space(which is within that range I am using currently) it will still say it is non-latin characters.

如何更改我必须执行的正则表达式?

How can I change the regular expression I have to do that?

推荐答案

只测试是否存在非ascii字符,而不是测试是否存在ascii字符:

Just test for the presence of non-ascii characters instead of testing for the presence of ascii characters:

var foreignCharacters = $("#foreign_characters").val();
var rforeign = /[^\u0000-\u007f]/;

if (rforeign.test(foreignCharacters)) {
  alert("This is non-Latin Characters");
} else {
  alert("This is Latin Characters");    
}

这篇关于我需要用什么正则表达式来检查一些非拉丁字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆