Reputation: 1274
This is my code. i want to check the input value with the array as prefixes and user must enter this any one array value as prefixes with its own value. js:
var per =["00162", "001187", "00188e", "002163", "002491"];
var isValid = false;
$.each(per , function(index,value) {
var i = [index];
console.log(i);
});
for(var j=0; j<i; j++) {
if(per[j] === value) {
isValid = true;
}
}
Upvotes: 0
Views: 33
Reputation: 74420
You should test a regex instead, for example still using an array for prefixes:
var per = ["00162", "001187", "00188e", "002163", "002491"];
var reg = new RegExp("^("+per.join('|')+")")
var isValid = reg.test(userInput);
Where userInput
is the value to test.
Upvotes: 1