This JavaScript function returns true if the characters from a string are valid, false otherwise. The characters for validation are given as a string parameter.
JavaScript code:
validateCharacters("Validate this", "abc");
function validateCharacters(str, allowedCharacters){
var characters = str.split("");
for (var i=0; i<characters.length; i++){
if (allowedCharacters.indexOf(characters[i]) == -1){
return false;
}
}
return true;
}