Browse project documentation

Postal code validation

Abzar0.8.1View sourceEnglish / Persian

Check Iranian postal-code patterns without an address lookup.

Eram\Abzar\Validation\PostalCode validates Iranian 10-digit postal codes.

Minimal example

Save beside vendor/ and run with PHP:

<?php
require 'vendor/autoload.php';

use Eram\Abzar\Validation\PostalCode;

$code = PostalCode::from('۱۶۱۹۷۳۵۷۴۴');
echo $code->value(), "\n";
echo $code->zoneCode(), "\n";
1619735744
16197

More examples

use Eram\Abzar\Validation\PostalCode;

PostalCode::validate('1619735744')->isValid(); // true
PostalCode::validate('16197-35744')->isValid(); // true — separators stripped
PostalCode::validate('۱۶۱۹۷۳۵۷۴۴')->isValid(); // true — Persian digits accepted

Rules

  • Exactly 10 digits after whitespace / dash stripping + digit normalization.
  • First digit must not be 0.
  • Fifth digit must not be 0.
  • No run of 4 or more identical digits anywhere.

Error codes

CodeWhen
POSTAL_CODE.EMPTYInput is empty after normalization
POSTAL_CODE.WRONG_LENGTHDoes not reduce to exactly 10 digits
POSTAL_CODE.INVALID_PATTERNFails first-digit, fifth-digit, or run-of-4 rules

Details

On success, detail() returns a PostalCodeDetails instance:

$pc = PostalCode::from('1619735744');
$pc->value();        // '1619735744'
$pc->zoneCode();     // '16197' (first 5 digits — mail zone)

// Via ValidationResult:
$detail = PostalCode::validate('1619735744')->detail();
$detail->postalCode; // '1619735744'
$detail->zoneCode;   // '16197'

Limitations and common mistakes

This checks a pattern, not a checksum or an address database. A passing code does not verify delivery or residence. Do not confuse any extracted ten-digit number with a confirmed postal address.

Related: validation, error handling, error codes.

Search documentation

Search across all projects. Close this window to return to your guide.

Tab to navigate · Enter to openEsc to close