0

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;
            }
        }

1 Answer 1

1

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.

DEMO jsFiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.