title: How do I perform string splitting in a form before submission?
body: <p>I have a form which requires the input data to be validated before submission. The types of validation checks - which can be more than 1 per input element - are entered into the input element, and the validation performed is by jQuery.</p>
  
  <p>My approach is to put all the types of validation that are required and separated by commas - such as "blank,email" - into the "checks" attribute of the input element. The jQuery will then extract this part, split it into an array, and loop through each validation type.</p>
  
  <p>The problem is, I do not want to submit the form until all the validation checks are completed. But when I use the "split" function, as it returns an array, the program takes it as a boolean true was returned and the form is submitted after the first input element.</p>
  
  <p>Here's a sample of the form, taking note that it looks similar with all other fields:</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-html lang-html prettyprint-override"><code>&lt;tr&gt;
    &lt;td&gt;Full Name&lt;/td&gt;
    &lt;td&gt;&lt;input type="TEXT" name="AccountName" check="blank"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;NRIC&lt;/td&gt;
    &lt;td&gt;&lt;input type="TEXT" name="AccountNRIC" check="blank,nric" maxlength="9"&gt;&lt;/td&gt;
  &lt;/tr&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's the jQuery validation code:</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>// PERFORM VALIDATION CHECKS
  $("form").submit(function()
                   {
    // LOOP THROUGH ALL INPUT FIELDS
    $("form input, form textarea, form select").each(function()
                                                     {
      // IF NONE OF THE INPUT'S PARENTS ARE HIDDEN
      if($(this).parents(":hidden").length == 0)
      {
        var thisValue = $(this).val();
        var checkWhat = $(this).attr("check");
        var checkArray = checkWhat.split(",");
        for(var i=0; i&lt;checkArray.length; i++)
        {
          switch(checkArray[i])
          {
            case "blank": alert(CheckBlank(thisValue)); break;
            case "nric": alert(ValidateNRIC(thisValue)); break;
            case "email": alert(ValidateEmail(thisValue)); break;
          }
        }
      }
    });
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>I should clarify that an error checking variable hasn't been added in yet as the codes are still being tested in parts.</p>
  
  <p>Any help is much appreciated!</p>