本文整理匯總了PHP中Respect\Validation\Validator::postalCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::postalCode方法的具體用法?PHP Validator::postalCode怎麽用?PHP Validator::postalCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::postalCode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fromString
/**
* @throws \InvalidArgumentException se o código de endereçamento postal (CEP)
* `$cepString` for inválido
*
* @param string $cepString
* @return self
*/
public static function fromString($cepString)
{
$cepString = (string) $cepString;
if (!Validator::postalCode('BR')->validate($cepString)) {
throw new \InvalidArgumentException(sprintf('O CEP `%s` é inválido', $cepString));
}
return new self($cepString);
}
示例2: validateAddress
public function validateAddress($address)
{
//@TODO: properly check all types.. strings need to be double checked for alnum, cause of typecasting.
$rules = v::key('firstname', v::notEmpty()->setName('First name'))->key('lastname', v::notEmpty()->setName('Last name'))->key('address', v::alnum(".,-'")->notEmpty()->setName('Address'))->key('secondary_address', v::when(v::notEmpty(), v::alnum(".,-'"), v::alwaysValid())->setName('Address 2'))->key('city', v::alnum()->notEmpty()->setName('City'))->key('state', v::alnum()->notEmpty()->setName('State'))->key('zip', v::when(v::notEmpty(), v::postalCode('US'), v::alwaysValid())->notEmpty()->setName('Zipcode'));
if ($rules->validate($address)) {
return true;
}
try {
$rules->check($address);
} catch (ValidationExceptionInterface $exception) {
// $this->error = $exception->getMainMessage();
}
return false;
}