Trying to validate if the user has entered a name starting with a letter, is at least 8 characters long, and has at least one number in it. See the code below:-
The first two conditions I have been able to make work, its validating whether or not there's a number within. I have tried to run a function all by itself with just the number validation in it but I cant seem to get it to work. this is my latest attempt to make it work, any help would be greatly appreciated, keep in mind I am a first year student :)
function nameVerify() {
var char1;
var char2;
var index;
var NL = "\n";
var valid = false;
char1 = useNam.substr(0, 1);
char1 = char1.toUpperCase();
char2 = useNam.substr(1);
for (index = 1; index <=useNam.length; index++){
while (!valid) {
if ((char1 <"A" || char1 >"Z") || (useNam.length <8) && (char2 >=0 || char2 <=9)){
alert("alert 1");
useNam = prompt("prompt 2");
char1 = useNam.substr(0, 1);
char1 = char1.toUpperCase();
char2 = useNam.substr(1);
}
else {
valid = true;
alert("Congragulations, you entered it correctly");
}
}
}}
var useNam;
useNam = prompt("prompt 1");
result = nameVerify(useNam);