title: Regex in jQuery validation - require a number with 5 digits and 1 letter (letter is not case sensitive)
body: <p>I'm trying to make a form with some validation. the one problem I have is the registration number validation. Each user already belongs to an association, so when they contact us we have to verify it's them by checking the number in the database. The help I need is with the regular expression on the registration no. </p>
  
  <p>The goal is to have them submit a Number with <strong>5 digits and 1 letter</strong>. The letter isn't case sensitive. So far I have tried this: </p>
  
  <pre><code>^(\d{5})([A-Z]{1})$
  </code></pre>
  
  <p>any number like 12345A would be acceptible.</p>
  
  <p>This validation seems a bit excessive but our users tend to insert the wrong information quite often and don't get to reply to emails straight away, so this way they can submit the correct details without us having to chase them for their correct information. </p>
  
  <p>Any help or pointing out errors is appreciated.</p>
  
  <p><strong>contact.js</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
    // Validate the contact form
    $('#contactform').validate({
      // Specify what the errors should look like
      // when they are dynamically added to the form
      errorElement: "label",
      wrapper: "td",
      errorPlacement: function(error, element) {
        error.insertBefore(element.parent().parent());
        error.wrap("&lt;tr class='error'&gt;&lt;/tr&gt;");
        $("&lt;td&gt;&lt;/td&gt;").insertBefore(error);
      },
  
      // Add requirements to each of the fields
      rules: {
        name: {
          required: true,
          minlength: 2
        },
        email: {
          required: true,
          email: true
        },
        RegNo: {
          required: true,
          minlength: 6
        },
        tuname: {
          required: true,
          minlength: 1
        },
        dob: {
          required: true,
          minlength: 10
        }
      },
  
      // Specify what error messages to display
      // when the user does something horrid
      messages: {
        name: {
          required: "Please enter your name.",
          minlength: jQuery.format("At least {0} characters required.")
        },
        email: {
          required: "Please enter your email.",
          email: "Please enter a valid email."
        },
        RegNo: {
          required: "Please enter your Reg No. (eg. 12345A)",
          minlength: jQuery.format("At least {0} characters required. eg. 12345A")
        },
        tuname: {
          required: "Please enter your Twitter Username.",
          minlength: jQuery.format("At least {0} characters required.")
        },
        dob: {
          required: "Please enter a DOB.",
          dob: jQuery.format("At least {0} characters required.")
        }
      },
  
      // Use Ajax to send everything to processForm.php
      submitHandler: function(form) {
        $("#send").attr("value", "Sending...");
        $(form).ajaxSubmit({
          success: function(responseText, statusText, xhr, $form) {
            $(form).slideUp("fast");
            $("#response").html(responseText).hide().slideDown("fast");
          }
        });
        return false;
      }
    });
  });
  
  strong text</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>&lt;?php
  
  // Clean up the input values
  foreach($_POST as $key =&gt; $value) {
   if(ini_get('magic_quotes_gpc'))
    $_POST[$key] = stripslashes($_POST[$key]);
   
   $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
  }
  
  // Assign the input values to variables for easy reference
  $name = $_POST["name"];
  $email = $_POST["email"];
  $RegNo = $_POST["RegNo"];
  $tuname = $_POST["tuname"];
  $dob = $_POST["DOB"];
  
  // Test input values for errors
  $errors = array();
  if(strlen($name) &lt; 2) {
   if(!$name) {
    $errors[] = "You must enter a name.";
   } else {
    $errors[] = "Name must be at least 2 characters.";
   }
  }
  if(!$email) {
   $errors[] = "You must enter an email.";
  } else if(!validEmail($email)) {
   $errors[] = "You must enter a valid email.";
  }
  if(strlen($RegNo) &lt; 6) {
     if(!$RegNo) {
        $errors[] = "You must enter a Reg Number. (e.g. 12345A)";
     } else {
        $errors[] = "Name must be at least 6 characters. (e.g. 12345A)";
     }
  }
  if(strlen($tuname) &lt; 2) {
     if(!$tuname) {
        $errors[] = "You must enter your twitter username.";
     } else {
        $errors[] = "Username cannot be blank.";
     }
  }
  if(strlen($DOB) &lt; 10) {
   if(!$DOB) {
    $errors[] = "You must enter a D.O.B.";
   } else {
    $errors[] = "D.O.B. must be at least 10 characters.";
   }
  }
  
  if($errors) {
   // Output errors and die with a failure message
   $errortext = "";
   foreach($errors as $error) {
    $errortext .= "&lt;li&gt;".$error."&lt;/li&gt;";
   }
   die("&lt;span class='failure'&gt;The following errors occured:&lt;ul&gt;". $errortext ."&lt;/ul&gt;&lt;/span&gt;");
  }
  
  // Send the email
  $to = "email@domain.com";
  $subject = "email subject";
  $message = "$name, $RegNo, $tuname, $dob";
  $headers = "From: $email";
  
  mail($to, $subject, $message, $headers);
  
  // Die with a success message
  die("&lt;span class='success'&gt;Success! Your message has been sent.&lt;/span&gt;");
  
  // A function that checks to see if
  // an email is valid
  function ValidatePPS($RegNo) {
  var formatRegex = /^(\d{7})([A-Z]{1,2})$/i;
  
  if (!formatRegex.test($RegNo)) {
  return "The format of the provided PPSN is invalid"; }
  }
  
  function validEmail($email)
  {
     $isValid = true;
     $atIndex = strrpos($email, "@");
     if (is_bool($atIndex) &amp;&amp; !$atIndex)
     {
        $isValid = false;
     }
     else
     {
        $domain = substr($email, $atIndex+1);
        $local = substr($email, 0, $atIndex);
        $localLen = strlen($local);
        $domainLen = strlen($domain);
        if ($localLen &lt; 1 || $localLen &gt; 64)
        {
           // local part length exceeded
           $isValid = false;
        }
        else if ($domainLen &lt; 1 || $domainLen &gt; 255)
        {
           // domain part length exceeded
           $isValid = false;
        }
        else if ($local[0] == '.' || $local[$localLen-1] == '.')
        {
           // local part starts or ends with '.'
           $isValid = false;
        }
        else if (preg_match('/\\.\\./', $local))
        {
           // local part has two consecutive dots
           $isValid = false;
        }
        else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
        {
           // character not valid in domain part
           $isValid = false;
        }
        else if (preg_match('/\\.\\./', $domain))
        {
           // domain part has two consecutive dots
           $isValid = false;
        }
        else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&amp;`_=\\/$\'*+?^{}|~.-])+$/',
                   str_replace("\\\\","",$local)))
        {
           // character not valid in local part unless 
           // local part is quoted
           if (!preg_match('/^"(\\\\"|[^"])+"$/',
               str_replace("\\\\","",$local)))
           {
              $isValid = false;
           }
        }
        if ($isValid &amp;&amp; !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
        {
           // domain not found in DNS
           $isValid = false;
        }
     }
     return $isValid;
  }
  
  function validateDate($dob)
  {
      $d = DateTime::createFromFormat('d-m-Y', $dob);
      return $d &amp;&amp; $d-&gt;format('d-m-Y') === $dob;
  }
  
  ?&gt;
  
  **index.html**</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="form-group" align="center"&gt;
    &lt;form id="contactform" action="processForm.php" method="post"&gt;
      &lt;table&gt;
        &lt;br&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;p&gt;
              &lt;label for="name"&gt;Full Name:&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" id="name" name="name" class="form-control" /&gt;
            &lt;/p&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;p&gt;
              &lt;label for="email"&gt;Email Address:&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;input type="email" id="email" name="email" class="form-control" /&gt;
            &lt;/p&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;p&gt;
              &lt;label for="RegNo"&gt;Garda Reg No:&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" id="RegNo" name="RegNo" class="form-control"&gt;&lt;/input&gt;
            &lt;/p&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;p&gt;
              &lt;label for="tuname"&gt;Twitter Username:&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;input type="text" id="tuname" name="tuname" class="form-control"&gt;&lt;/input&gt;
            &lt;/p&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;p&gt;
              &lt;label for="dob"&gt;D.O.B:&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
            &lt;input type="date" id="dob" name="dob" class="form-control" placeholder="00/00/00"&gt;&lt;/input&gt;
            &lt;/p&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;
            &lt;p&gt;
              &lt;input type="submit" value="Send!" id="send" type="button" class="btn btn-primary" /&gt;
            &lt;/p&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/form&gt;
    &lt;div id="response"&gt;&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>