How can I determine if any individual character in src matches any individual character in restricted? I have this JS method which does the job, but I'd like to improve it if I can:
function CheckRestricted(src, restricted) { for (var i = 0; i < src.length; i++) { for (var j = 0; j < restricted.length; j++) { if (src.charAt(i) == restricted.charAt(j)) return false; } } return true; } If this were C#, I could achieve this with LINQ in a single line:
bool CheckRestricted(string src, string restricted) { return src.Any(s => restricted.Contains(s)); } Is there some sort of similar functionality in JS that I'm unaware of?
EDIT: Sample use case:
CheckRestricted("ABCD", "!+-=;:'`"); //true CheckRestricted("ABCD!", "!+-=;:'`"); //false It is predominantly used to disallow 'special characters'.