I have a page where admins can set up words that are blacklisted and not allowed to be used in email addresses. On the signup page, I have an array populated with all of those words. This page is internal and is for requesting multiple email addresses to be created so for each of the requested email addresses, I need to see if the word exists in the array.
I can do this with the typical jQuery inArray
, however I need to figure out how to implement partial matches as well.
-- Example
var blackList = Array('admin', 'webform', 'spam');
... Loop over the requested email addresses and put them into an array
var requestedEmails = Array('dogs@cats.com', 'webform1@cats.com', 'admins@cats.com');
// Check for the exact match in the arrays
$(requestedEmails).each(function(){
if(jQuery.inArray(this, blackList) != -1) {
// Word is in the array
} else {
// Word is not in the array
}
});
In the example above, I would need it to catch webform1
and admins
as both of those words exist in the blacklist in some way.
What is the best way to add in the partial matches from here?