title: Rails conditional validation of Zip Code for many countries
body: <p>I need a model-level validation for Zip codes in USA and Canada. This code makes me feel bad:</p>
  
  <pre><code>zip_regex_usa = %r{\d{5}(-\d{4})?}
  zip_regex_canada = %r{[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d}
  
  validates :shipping_zip, :presence =&gt; true, :format =&gt; { :with =&gt; zip_regex_usa }, :if =&gt; :shipping_to_usa?
  validates :shipping_zip, :presence =&gt; true, :format =&gt; { :with =&gt; zip_regex_canada }, :if =&gt; :shipping_to_canada?
  validates :billing_zip, :presence =&gt; true, :format =&gt; { :with =&gt; zip_regex_usa }, :if =&gt; :billing_to_usa?
  validates :billing_zip, :presence =&gt; true, :format =&gt; { :with =&gt; zip_regex_canada }, :if =&gt; :billing_to_canada?
  
  def shipping_to_usa?
    shipping_country == 'US'
  end
  
  def billing_to_usa?
    billing_country == 'US'
  end
  
  def shipping_to_canada?
    shipping_country == 'CA'
  end
  
  def billing_to_canada?
    billing_country == 'CA'
  end
  </code></pre>
  
  <p>How to make this code more elegant, writing a single validation line for each field?</p>