title: How to use Javascript to check that user input includes a capital letter, lowercase letter, number and is between 8-12 characters?
body: <p>I am learning Javascript and having trouble with an assignment.
  I'm supposed to create Javascript code that checks if user input is valid. The instructions say</p>
  <blockquote>
  <p>Ask the user to input their first name, last name, a UserID, and a birthdate in type date format.  The UserID must contain an uppercase, a lowercase, a number, and be 8 to 12 chars long.  Create a JS function to verify formats of the UserID field.You will need to use Loop For to iterate through your data fields character by character, and JS functions like char.toUpperCase() and parsInt(char) or RegExp() to validate the UserID format.</p>
  </blockquote>
  <p>I have no idea how to do that. I have tried something like this</p>
  <pre><code>&lt;form id = &quot;myForm&quot; action=&quot;&quot;&gt;
    &lt;label for=&quot;uid&quot;&gt;User Id:&lt;/label&gt;
    &lt;input type=&quot;name&quot; id=&quot;uid&quot; name=&quot;uid&quot;&gt;&lt;br&gt;
    &lt;label for =&quot;fname&quot;&gt; First Name:&lt;/label&gt;
    &lt;input type = &quot;text&quot; id=&quot;fname&quot; name=&quot;fname&quot;&gt;&lt;br&gt;
    &lt;label for=&quot;lname&quot;&gt;Last name:&lt;/label&gt;
    &lt;input type=&quot;text&quot; id=&quot;lname&quot; name=&quot;lname&quot;&gt;&lt;br&gt;
    &lt;label for =&quot;birthday&quot;&gt; Birthday:&lt;/label&gt;
    &lt;input type=&quot;date&quot; id=&quot;birthday&quot; name = &quot;birthday&quot;&gt;&lt;br&gt;
    &lt;input type=&quot;submit&quot; id = &quot;accept&quot; value=&quot;Accept&quot;&gt;
  &lt;/form&gt;
  
  &lt;div id = &quot;validate&quot;&gt;
  &lt;/div&gt;
  &lt;script&gt;
  form.onsubmit = function() {
    let uIdText = document.getElementById('uId');
    let pattern = \d;
    let result = pattern.test(uidText);
    if result = true {document.getElementById(&quot;validate&quot;).innerHTML = &quot;Valid User ID&quot;}
    else document.getElementById(&quot;validate&quot;).innerHTML = &quot;UserID needs to include a number&quot;;
  &lt;/script&gt;
  </code></pre>
  <p>But that does not work, and it doesn't use a loop.</p>
  <p>*UPDATE:
  I tried this</p>
  <pre><code>var uIdText = document.getElementById(uId).innerHTML;
  var myForm = document.getElementById(myForm).innerHTML;
  var result = document.getElementById(validate).innerHTML;
  myForm.onsubmit = function validate(uIdText) {
    uIdLength();
    /regexp(?=.[a-z])(?=.\d)(?=.[A-Z]);
  }
  function uIdLength(uIdText){
    if uIdText.legth &gt;=8 &amp;&amp; &lt;=12 == true;
      then result = &quot;Form Submitted&quot;;
      else result = &quot;Invalid User Id&quot;
  }
  validate(uIdText);
  </code></pre>
  <p>but that also did not work.</p>