/** * Only validate the zip / postal code for countries * that have a defined postcode pattern matching rule * in the db * @param $attribute The attribute name. * @param $params Additional parameters defined in the rules. * @return void */ public function validatePostal($attribute, $params) { $validate = false; $objCountries = Country::model()->withpostal()->findAll(); if ($attribute == 'shippingPostal') { $country = $this->shippingCountry; } if ($attribute == 'billingPostal') { $country = $this->billingCountry; } if (empty($country)) { return; } foreach ($objCountries as $objCountry) { if ($country === $objCountry->id) { $validate = true; break; } } if ($validate === true) { parent::validatePostal($attribute, $params); } return; }