名前を入力する際にフォームの検証を少し作成しようとしています 特定の文字、既に作成された名前、および内部予約語は許可しません。問題は、私が "pos"にマッチして失敗したという名前の中に "posts"を入れたいと言うことです。エラーのためにjavascript内の単語だけを一致させたい
if (filterName.match("\\b"+badchar[char]+"\\b"))
\b
ため
var badchar = new Array('"', "," , "'" , "#", "&", "!", "@", "$", "+", ";", ":", "*", "(",")", "[","]","{","}", "/", "=");
var resword = new Array("positive","pos","negative","neg","neutral", "neu","twitter","itunes","facebook","android","forums","RSS Feeds");
var existingNames = @anames;
var valueLen = $("#aname").val().length;
var fail=false;
var filterElem = $('#aname');
var filterName = $('#aname').val();
$.each(badchar, function(char){
if (filterName.indexOf(badchar[char]) != -1) {
console.log("bad character")
filterElem.css('border','2px solid red');
window.alert("You can not include '" + badchar[char] + "' in your Filter Name");
fail = true;
}
});
$.each(resword,function(){
if (filterName.match(this)) {
console.log("bad word");
filterElem.css('border','2px solid red');
window.alert("You can not include '" + this + "' in your Filter Name");
fail = true;
}
});
フォームのコンテキストと検証を使用している特定の入力とは何ですか? – RobB