用于检测非ascii字符的Java Script正则表达式 [英] Java Script regular expression for detecting non-ascii characters
本文介绍了用于检测非ascii字符的Java Script正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用java脚本限制在特定文本字段中使用非ascii字符..?提前谢谢...
How can we use java script to restrict the use of non-ascii characters in a specific text field..? thanks in advance...
推荐答案
Ascii被定义为000-177(八进制)范围内的字符,因此
Ascii is defined as the characters in the range of 000-177 (octal), therefore
function containsAllAscii(str) {
return /^[\000-\177]*$/.test(str) ;
}
您可能不想接受非打印字符 \000-\ 037
,也许你的正则表达式应该是 / \040-\0176 /
You probably don't want to accept non-printing characters \000-\037
, maybe your regex should be /\040-\0176/
这篇关于用于检测非ascii字符的Java Script正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文