I have this part of a html code:
<tr>
<td id="examnumber">Examination number</td>
</tr>
<tr>
<td><input type="text" name="examnumber"/></td>
</tr>
And I need the number entered to be 4 digits long and between the range 0000-9999. I have attempted to validate it by using this javascript code:
function validateForm() {
var result = true;
var msg="";
if (document.ExamEntry.examnumber.value=="") {
msg+="You must enter your examination number. \n";
document.ExamEntry.examnumber.focus();
document.getElementById('examnumber').style.color="red";
} else if ((document.ExamEntry.examnumber.value.length < 0) || (document.ExamEntry.examnumber.value.length > 9999)) {
msg+= "The examination number is not within the range 0000-9999.\n";
result = false
}
if (document.ExamEntry.examnumber.value.length!=4) {
msg+="Your examination number must be 4 digits long. \n";
document.ExamEntry.examnumber.focus();
document.getElementById('examnumber').style.color="red";
result = false;
}
However when I test the code by entering -900 or 3.45, it doesn't come up with an error message and says that the information has been entered correctly. I would very much appreciate it if someone could help me to fix this error.