title: NIC and username validation field
body: <p>I have two fields, the NIC and the username. Their validation are</p>
  
  <ul>
  <li>NIC check for numbers or characters</li>
  <li>username field must contain more than 8 characters including the date
  of birth from the NIC.</li>
  </ul>
  
  <p>So far I tried this for my NIC.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function validateNIC() 
  {
      var nic = document.getElementById('NIC');
      var mesg = document.getElementById('message1');
  
       if (NIC.length != 14) {
          message1.innerHTML="Length must be 14 characters";
      } else{
          message1.innerHTML="Length is good";
      }
      }
      </code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;div class="form-group"&gt;
                  &lt;label for="username"&gt;&lt;span class="req"&gt;* &lt;/span&gt; NIC NUMBER:&lt;/label&gt; 
                      &lt;input class="form-control" type="text" name="NIC" id = "NIC" required onkeyup = "validateNIC();" maxlength=14  /&gt;  
                      &lt;span id="message1"&gt;&lt;/span&gt;
                          
              &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And for my username I tried this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function Validate(txt) {
    txt.value = txt.value.replace(/[^a-zA-Z-'\n\r.]+/g, '');
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="form-group"&gt;
    &lt;label for="username"&gt;&lt;span class="req"&gt;* &lt;/span&gt; User name:&lt;/label&gt;
    &lt;input class="form-control" type="text" name="username" id="txt" onkeyup="Validate(this)" maxlength=14 required /&gt;
    &lt;div id="errLast"&gt;&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <ul>
  <li>My validation for the NIC is not quite working.It keeps showing
  "Length must be 14 characters" even if the length is good.</li>
  <li>And for the username part,  can anyone tell me how to do it ? Is
  there an array I must do or something ? An example of the NIC is
  T2108974302906 where 210897 is the DOB.</li>
  </ul>