 <p>Move the regex matching into a method.</p> <p>You could associate the regex with a key in a hash, too, making this easier, roughly:</p> <p>EMAILS = { "Berkeley": /\A[\w+-.]+@berkeley.edu\z/i, "Washington": /whatever/ }</p> <p>Iterate over the hash to get the value and regex:</p> <pre><code>EMAILS.each do |school, regex| # If it matches, return the `school` value end </code></pre> <p>Use the <em>same</em> method for your email validation by validating <code>:email</code> against the method instead of a simple regex as detailed in the <a href="http://guides.rubyonrails.org/active_record_validations.html#performing-custom-validations" rel="nofollow">Custom Validation section of the Active Record Validations Guide</a>. You may need to tweak the return value etc. to get the function to work for both things, or write a thin wrapper for the validation around the lookup.</p> <p>Consider a callback to actually set the value, e.g., <code>:after_validation</code> or <code>:before_save</code>.</p>