Hi people!
I’m sorry for my bad english, please answer me in simple words.
I’m trying to validate an input type text html tag with JS.
There is an array (prefisso[]) with a lot of dial codes.
The first 3 characters of the value to check must be one of the elements of “prefisso[]”.
The value to check must be longer than 9 chars (min 10).
Were I’m wrong?
thank you!
[CODE]
function verifytel(elem) {
var prefisso=new Array();
prefisso[0]=”331″;
// …
// FOLLOWS A LOT OF DIAL CODES
// …
prefisso[36]=”377″;
prefisso[37]=”331″;
prefisso[38]=”377″;
var check=false;
if(!isNaN(elem.value)) {
if((elem.value.length>=10)) {
for(var i=0; i<prefisso.length; i++) {
if(elem.value.startsWith(prefisso[i])==true) {
check=true;
elem.style.backgroundColor=”#00ff00″;
}
}
if(check==false) alert(“Invalid telephone number.”);
}
}
else alert(“Please insert only numbers, no dots, blank spaces, etc.”);
}