The objective of this code is to check the name the user inputs. If the value contains something other than -abcdefghijklmnopqrstuvwxyz'ABCDEFGHIJKLMNOPQRSTUVWXYZ the function will throw an error.
I am unable to get this to work, and I'm not allowed to use Regular expressions. I've also tried String1.indexOf(usr.substr(i,1)) > -1) but that doesn't seem to work neither.
function nameValidation(username) {
var usr = document.getElementById("username").value;
usr = usr.trim();
var alpha = "-abcdefghijklmnopqrstuvwxyz'ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var ok = 1;
for (var i = 0; i < usr.length; i++) {
if (!isNaN(usr[i])) {
ok = 0;
break;
} else {
ok = 1;
document.getElementById("fnerror").innerHTML = "";
document.getElementById("username").style.borderColor = "lightgrey";
return true;
}
}
if (ok == 0) {
document.getElementById("fnerror").innerHTML = "X Enter Upper and lower case letters, hypen, apostrohe only please";
return false;
}
return true;
}
/[^azAZ-']/?/[^A-z-']/