title: I wish to make my code validate a field to make sure it is a number of four digits. How can I do this?
body: <p>I am currently doing a GCSE course which allows me to ask for assistance from IT sources as long as I reference them in my investigation. I wish to make the following code validate that there is a number of four digits in the Examination Number entry field. I'm okay with simple validation but this is another step for me.</p>
  
  <pre><code>    &lt;head&gt;
  &lt;title&gt;Exam entry&lt;/title&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  
  function validateForm() {
  var result = true;
  var msg="";
  if (document.ExamEntry.name.value=="") {
  msg+="You must enter your name \n";
  document.ExamEntry.name.focus();
  document.getElementById('name').style.color="red";
  result = false;
  }
  
  if (document.ExamEntry.subject.value=="") {
  msg+="You must enter the subject \n";
  document.ExamEntry.subject.focus();
  document.getElementById('subject').style.color="red";
  result = false;
  }
  
  if (document.ExamEntry.examnumber.value=="") {
  msg+="You must enter your Examination Number \n";
  document.ExamEntry.examnumber.focus();
  document.getElementById('examnumber').style.color="red";
  result = false;
  }
  
  var checked = null;
  var inputs = document.getElementsByName('examtype');
  for (var i = 0; i &lt; inputs.length; i++) {
            if (inputs[i].checked) {
             checked = inputs[i];
  document.getElementById('examtype').style.color="red";
     }
  }
  if(checked==null)
  {
      msg+="Please choose an option";
      result = false;
  }
  else{
       confirm("You have chosen "+checked.value+" is this the correct course?"); 
  }
  
  if(msg==""){
  return result;
  }
  {
  alert(msg)
  return result;
  }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Exam Entry Form&lt;/h1&gt;
  &lt;form name="ExamEntry" method="post" action="success.html"&gt;
  &lt;table width="50%" border="0"&gt;
  &lt;tr&gt;
  &lt;td id="name"&gt;Name&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="name" /&gt;&lt;/td&gt;
  &lt;tr&gt;
  &lt;td id="subject"&gt;Subject&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="subject" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td id="examnumber"&gt;Examination Number&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="examnumber" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type="radio" id="examtype" name="examtype" value="GCSE" /&gt; : GCSE&lt;br /&gt;
  &lt;td&gt;&lt;input type="radio" id="examtype" name="examtype" value="A2" /&gt; : A2&lt;br /&gt;
  &lt;td&gt;&lt;input type="radio" id="examtype" name="examtype" value="AS"/&gt; : AS&lt;br /&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type="submit" name="Submit" value="Submit" onClick="return validateForm();"    /&gt;  &lt;/td&gt;
  &lt;td&gt;&lt;input type="reset" name="Reset" value="Reset" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>