title: rails 3 validation for a comma-separated list of email addresses
body: <p>I'm a total newbie at Rails validation, and while I've seen some related questions, I cannot figure how to extend them to my situation.</p>
  
  <p>I need to allow a user setting up their account to enter up to N (a system wide constant, like 10) optional email addresses.</p>
  
  <p>so the data a user would enter into the text field might look like</p>
  
  <pre><code>foo@bar.com
  </code></pre>
  
  <p>or </p>
  
  <pre><code>foo@bar.com, foo2@bar2.com,foo3@bar3.com , foobar4@domain.com
  </code></pre>
  
  <p>(note inconsistent use of space before or after comma, typical real-user stuff)</p>
  
  <p>currently in my model I handle single optional email and use a regex :</p>
  
  <pre><code>validates :alert_email,
      :allow_blank =&gt; true,
      :length =&gt; {:minimum =&gt; 3, :maximum =&gt; 254},
      :format =&gt; {:with =&gt; /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
  </code></pre>
  
  <p>There is probably some sort of uber-regex that I could replace mine with... and that would be fine if anyone can help. However for readability (and because performance is irrelevant since this is done once per user) I think I should somehow move the validation to a method that brute force parses them out and runs the regex one at a time?</p>
  
  <p>PS I would also like my validation routine to "fix up" the space/comma thing, so it's always comma-space between items in the list, and have that fixed-up version be what's saved. I'm guessing I do some before_xxxxx method?</p>