new to this so hopefully my question is specific enough for it to make sense.
I am trying to create a webpage that validates a "Student Number" ---
- must start with an "A"
- following the A there must be exactly 8 numerical digits,
- but they cannot be all 0's
For example A89071231 would be a valid student number, but A00000000 would not be, nor would just "A" or "A123".
The user's input must be A + exactly 8 digits that are not all zeros.
What I have so far is this below. Where "StudentNo" = an HTML id tag and the "calculate" function is to total the students grade average.
I just need help figuring out how to write the code so that each digit following the first character A can be anything between 0-9 and still give a valid input, besides a situation where the user inputs all 0's after the "A".
I figured regex would be the easiest way to do it, or by using substr() or substring() but I am not very familiar with JavaScript and can't seem to figure out where I am going wrong with it.
Thanks for any help you can give!!!
function calculate();
var sno = $("StudentNo").value.trim();
if(sno === "" || !sno.startsWith("A") {
alert("Student Number is missing, please enter your Student A Number.");
$("StudentNo").focus();
return;
}