Javascript 当.UK被阻止时,RegExp也阻止了UK
这是我的RegExpJavascript 当.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
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);
}