Reputation: 171
Trying to create a javascript method like below , where the input html will be scanned and log there if any of the entry in the list was found ..
why this specific because , we have to allow somemarkup like < or > or some html keywords , thats why
created this fiddle for this https://jsfiddle.net/ronqLes5/
JS
var input ;
$( "#target" ).click(function() {
var identifier =false;
input= $("#textbox1").val();
console.log(input.toLowerCase());
var untrustedInput = ["script","jquery", "$", "Javascript","location","href"];
for (var i = 0; i < untrustedInput.length ; i++) {
if (input.toLowerCase().indexOf(untrustedInput[i].toLowerCase())> -1) {
identifier =true;
}
}
if(identifier){
console.log("there");
}
else
{
console.log("not there");
}
});
would like to know if you have any faster and convenient way is there or any kind of suggestion.
is there any more keywords you think i should enter it in the list.
Upvotes: 0
Views: 55
Reputation: 2129
Use only indexOf:
function CustomHtmlEndoder(input) {
var untrustedInput = "<script>,</script>,jquery,$,Javascript,location,href";
if (input.Indexof(untrustedInput)>=0) {
return false;
}
else{
return true;
}
}
Upvotes: 1