i write a routine which validate input. it is working fine but when i enter character a then it just accept. here is my code.
function isValidPhoneNumber(val) {
var flag = true;
var invalidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@!$#";
if (flag) {
for (index = 0; index <= val.length - 1; index++) {
var phchars = val.substring(index, index + 1);
if (invalidChars.indexOf(phchars) > 0) {
flag = false;
break;
}
}
}
return flag;
}
suppose if i gave val='+9122a5669974' then it return true. indexof function not being able to find the a....why. please tell me what is wrong in the routine. if any char found which exist in invalidChars variable then routine should return false but when a found then routine return true. help me to catch the error. thanks