<p>According to Luke, this is the preferred method for Commerce 3.</p>

<p>In a custom module or plugin:</p>

<pre><code>Event::on(\craft\commerce\models\Address::class, \craft\base\Model::EVENT_DEFINE_RULES, static function(\craft\events\DefineRulesEvent $event) {
    $rules = $event-&gt;rules;
    $rules[] = [['firstName','lastName'], 'required'];
    $event-&gt;rules = $rules;
});
</code></pre>

<p>Some more details about what kind of rules you can add here, if you want something more complex than a list of required fields:
<a href="https://www.yiiframework.com/doc/guide/2.0/en/tutorial-core-validators" rel="nofollow noreferrer">https://www.yiiframework.com/doc/guide/2.0/en/tutorial-core-validators</a></p>

CC BY-SA 4.0
2020-02-06T18:43:35.963Z
thanks @Gterrill
Luke Holder
CC BY-SA 4.0
2020-02-06T18:25:37.523Z
2020-02-06T18:25:37.523Z
GTerrill
<p>Was wondering how to do this in Commerce 3 as there were a few different older methods discussed here.</p>

<plugin-craftcommerce><validation><plugin-craftcommerce3>
Server-side address validation in Craft Commerce 3
# Server-side address validation in Craft Commerce 3

(Asked by: username_0 on 2020-02-06)

Was wondering how to do this in Commerce 3 as there were a few different older methods discussed here.

**Tags:** plugin-craftcommerce, validation, plugin-craftcommerce3


---

## 1 answers

### Answer by username_0 on 2020-02-06. Score: 2

According to Luke, this is the preferred method for Commerce 3.
In a custom module or plugin:
Event::on(\craft\commerce\models\Address::class, \craft\base\Model::EVENT_DEFINE_RULES, static function(\craft\events\DefineRulesEvent $event) {
    $rules = $event->rules;
    $rules[] = [['firstName','lastName'], 'required'];
    $event->rules = $rules;
});

Some more details about what kind of rules you can add here, if you want something more complex than a list of required fields:
https://www.yiiframework.com/doc/guide/2.0/en/tutorial-core-validators

> **Comments:**
> **username_1**: thanks @Gterrill  

---

