Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当.UK被阻止时,RegExp也阻止了UK_Javascript_Php_Regex_Validation - Fatal编程技术网

Javascript 当.UK被阻止时,RegExp也阻止了UK

Javascript 当.UK被阻止时,RegExp也阻止了UK,javascript,php,regex,validation,Javascript,Php,Regex,Validation,这是我的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(abou

这是我的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;   
            }
这阻止了UK,com和.UK.com我做错了什么

m使用测试作为文本:-


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

在正则表达式中表示“任何字符”


使用
“\\.uk”

就像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')))

将此功能更改为:

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