Answers.Body: <p>You can do either or both of:</p>
  
  <ol>
  <li><p>Use javascript validation on the front end (with e.g. <a href="http://parsleyjs.org/">parsley</a>)</p></li>
  <li><p>Create a plugin with a method that is registered as a listener on this event:
  <a href="https://craftcommerce.com/docs/events-reference#commerce_addresses.onbeforesaveaddress">https://craftcommerce.com/docs/events-reference#commerce_addresses.onbeforesaveaddress</a></p></li>
  </ol>
  
  <p>...and perform validation on the address model before it is saved.  use <code>$event-&gt;performAction = false;</code> to stop the address actually being saved if need be.</p>
  
  <p>General notes on how to listen to events and get at parameters is <a href="https://craftcms.com/docs/plugins/hooks-and-events#events">here</a>.</p>
  
  <p>Most likely, the best way will be to use a bit of both front end and back end validation here to make sure you're getting the data you want in the format you want in to your address fields.</p>
  
  <p>(If you don't yet have a business logic plugin for your Commerce setup, then create one using either of two excellent options:
  <a href="https://github.com/lindseydiloreto/craft-businesslogic">Business Logic Plugin</a> or via <a href="http://pluginfactory.io">http://pluginfactory.io</a>)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-09T00:12:36.057Z
Answers.LastActivityDate: 2016-05-09T00:12:36.057Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>How/Where/Can I add more address model validations than just "firstName" and "lastName"...?</p>
  
Tags: <validation><models><ecommerce>
Title: Craft Commerce: Custom address model validations
ThreadText: # Craft Commerce: Custom address model validations
  
  (Asked by: username_0 on 2016-05-09)
  
  How/Where/Can I add more address model validations than just "firstName" and "lastName"...?
  
  **Tags:** validation, models, ecommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-09. Score: 4 | Accepted answer
  
  You can do either or both of:
  
  1. Use javascript validation on the front end (with e.g. [parsley](http://parsleyjs.org/))
  2. Create a plugin with a method that is registered as a listener on this event:
     <https://craftcommerce.com/docs/events-reference#commerce_addresses.onbeforesaveaddress>
  
  ...and perform validation on the address model before it is saved. use `$event->performAction = false;` to stop the address actually being saved if need be.
  
  General notes on how to listen to events and get at parameters is [here](https://craftcms.com/docs/plugins/hooks-and-events#events).
  
  Most likely, the best way will be to use a bit of both front end and back end validation here to make sure you're getting the data you want in the format you want in to your address fields.
  
  (If you don't yet have a business logic plugin for your Commerce setup, then create one using either of two excellent options:
  [Business Logic Plugin](https://github.com/lindseydiloreto/craft-businesslogic) or via <http://pluginfactory.io>)
  
  
  ---
  
  