I have a list of names, and I need a function so that the user can filter them using wildcards * and? (any string and any character.) I know that I need to clear user input to avoid syntactic injections (intentional or random), but I don't know how much I need to clear.
Why do I need to replace * and? from user input?
var names = [...]; var userInput = field.value; userInput = userInput.replaceAll(...); userInput = userInput.replaceAll(...); userInput = userInput.replaceAll(...); userInput = userInput.replaceAll(...); ... var regex = new Regexp(userInput); var matches = []; for (name in names) { if (regex.test(name)) { matches.push(name); } }
Thanks.
source share