RegExp也在封锁英国.英国将被封锁

RegExp is also blocking UK when .UK is ment to be blocked

本文关键字:英国 封锁 RegExp      更新时间:2023-09-26

这是我的RegExp

    function wordInString(s, word){
          return new RegExp( '''b' + word + '''b', 'i').test(s);
    }
var about=jQuery('#compdesi').val();
            var education=jQuery('#educationhistory').val();
            if((wordInString(about, '@')==true) || (wordInString(about, '.com')==true) || (wordInString(about, '.co')==true) || (wordInString(about, '.org')==true) || (wordInString(about, '.net')==true) || (wordInString(about, '.info')==true) || (wordInString(about, '.au')==true) || (wordInString(about, '.uk')==true) || (wordInString(about, '.ac')==true))
            {
                alert("You can not enter website, email or phone number in about");
                return false;   
            }

这是在屏蔽英国网站和英国网站我做错了什么!

m使用测试作为文本:-

他出生于英国迈阿密的一个艺术家家庭,对他的绘画产生了深远的影响。现在经常在非洲。

.在正则表达式中的意思是"任何字符"。

使用"''.uk"

将此函数更改为:

function wordInString(s, word){
      return new RegExp( '''b''''' + word + '''b', 'i').test(s);
}

正如dystroy所说,除了需要双重转义外,请尝试以下行:

if ((wordInString(about, '@')) 
    || (wordInString(about, '''.com')) 
    || (wordInString(about, '''.co')) 
    || (wordInString(about, '''.org')) 
    || (wordInString(about, '''.net')) 
    || (wordInString(about, '''.info')) 
    || (wordInString(about, '''.au')) 
    || (wordInString(about, '''.uk')) 
    || (wordInString(about, '''.ac')))