title: Date of birth regex yyyy-mm-dd for rails app
body: <p>I am creating a user signup form, and I am adding date of birth to the required fields.</p>
  
  <p>I have scoured google, github and stackoverflow for a good date of birth (date) regex, and found this:</p>
  
  <p><em><strong>user.rb</em></strong></p>
  
  <pre><code>DateRegex = /^\d{4}-\d{2}-\d{2}/
  
  validates_format_of :date_of_birth, :with =&gt; DateRegex
  </code></pre>
  
  <p><em><strong>new.html.erb</em></strong></p>
  
  <pre><code>&lt;%=label_tag :date_of_birth %&gt;
  &lt;%=f.text_field :date_of_birth %&gt; 
  </code></pre>
  
  <p>(I know that this will allow some bogus birth dates, but I prefer not to install anything like validate timeliness at this point.)</p>
  
  <p>However, when testing the date of birth, it doesn't seem to enforce the 4-2-2 in the regex. It allows 2-2-2 sometimes, 2-4-2, 2-2-4, and it allows hyphens and slashes...help please?</p>
  
  <p>Also, if necessary, how to I use 3 text fields and have it enter into one mysql date_of_birth column?</p>