My current project involves creating a system that requires users to input multiple names of their choosing. To ensure the validity of these names, I am looking to develop a "name verifier" that checks if all characters in the entered string are either letters (both lowercase and uppercase), numbers, or a few select special characters (such as , : . * _ - +).
One approach I considered was to define a large constant array containing all permitted characters and then iterate over the input string using the following method:
for (i = 0; i < name.length; i++){
if (permitted_chars.indexOf(name[i]) === -1) return false;
}
return true;
However, given the potentially extensive size of both the array of permitted characters and the names themselves (not to mention the effort required to create the array), this approach seems impractical.
Are there any alternative methods that could be more efficient?