shaswatatripathy
shaswatatripathy

Reputation: 171

Javascript Encoding method with specific keywords

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");
    }
});
  1. would like to know if you have any faster and convenient way is there or any kind of suggestion.

  2. is there any more keywords you think i should enter it in the list.

Upvotes: 0

Views: 55

Answers (1)

DIEGO CARRASCAL
DIEGO CARRASCAL

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

Related Questions