I am trying to learn if there is a javascript method to search a string to see if that string contains any of the values in an array of strings.
An example would be:
var a = 'How now brown cow';
var b = new Array('red', 'green', 'brown');
The resulting function would return true because the word brown is contained within the string a
.
More specifically what I am trying to do (except using values from form input) is:
var a = '12345@gmail.com';
var b = new Array('.com', '.net', '.org');
This should also return true. Then based on this I will go on to accept var a
as valid.
My actual code as of right now (which always returns null
) is as follows:
function check_domain(){
for(var i=0; i<domains.length; i++){
var d = domains[i];
if(elemen.value.indexOf(d) != d){
return null;
}
else{
vEmail.style.visibility = 'visible';
}
}
}
window.domains = new Array(....Array values here....);