title: Regexp for a name
body: <p>I need to make sure people enter their first, middle and last names correctly for a form in Rails. So the first thought for a regular expression is:</p>
  
  <pre><code>\A[[:upper:]][[:alpha:]'-]+( [[:upper:]][[:alpha:]'-]*)*\z
  </code></pre>
  
  <p>That'll make sure every word in the name starts with an uppercase letter followed by a letter or hyphen or apostrophe.</p>
  
  <p>My first question I guess doesn't have much to do with regular expressions, though I'm hoping there's a regular expression I can copy for this. Are letters, hyphens and apostrophes the only characters I should be checking in a name?</p>
  
  <p>My second question is if it's important to make sure each name has at least 1 uppercase letter? So many people enter all lowercase names and I really want to avoid that, but is it sometimes legitimate?</p>
  
  <p>Here's what I have so far that makes sure there's at least 1 uppercase letter somewhere in the name:</p>
  
  <pre><code>\A([[:alpha:]'-]+ )*[[:alpha:]'-]*[[:upper:]][[:alpha:]'-]*( [[:alpha:]'-]+)*\z
  </code></pre>
  
  <p>Isn't there a [:name:] bracket expression? :)</p>
  
  <p><em><strong>UPDATE</em></strong>: I added <code>.</code> and <code>,</code> to the characters allowed, surprised I didn't think of them originally. <strong>So many</strong> people must have to deal with this kind of regular expression! Nobody has any pre-made regular expressions for this sort of thing?</p>