title: PHP Checking the length of a SSN
body: <p>We're trying to setup an online application for our admissions office and we need to error check Social Security Numbers to make sure they've entered a valid value. Either <code>xxx-xx-xxxx</code> or just 9 digits. I've tried several iterations and this is what I'm on right now:</p>
  
  <pre><code>$ssn = $form_values['submitted_tree']['biographical_information']['social_security_number'];
  
  if (strlen($ssn) &gt; 0 &amp;&amp; preg_match('/^([0-9]){3}(([ ]|[-])?([0-9]){2})(([ ]|[-])?([0-9]){4})?$/', $ssn) == 0) { 
      form_set_error('submitted][biographical_information][social_security_number', t('You must enter a valid Social Security Number: ###-##-####')); 
  }
  </code></pre>