Regular Expressions 101

Community Patterns

Matching an Saudi Postal Code

1

Regular Expression
PCRE (PHP <7.3)

/
^[A](([A-Z]|[0-9])?([A-Z]|[0-9])?([A-Z]|[0-9]))\s[0-9][A-Z][A-Z]$
/
gm

Description

Saudi Postal Code has five digits, if you would to have more information check the below: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

First Digit (Postal Regions): "The postal region number is represented by the first digit of the postal code"

The kingdom is divided into 8 postal regions. The division was based on the country's administrative regions. The numbering of the postal regions differs from that of the administrative regions in the kingdom. The Postal Division was based on the consideration of road connectivity network and other geographical factors. The below table shows the list of Postal Regions in the country: 1 Arriyadh Region 2 Makkah Region 3 Eastern Provience Region 4 Madinah and Tabuk 5 Qassim and Ha'il 6 Asir, Najran, and Bahah 7 Northern Borders, and Jawf 8 Jizan


Second Digit (Postal Sectors): "The postal sector number is represented by the second digit of the postal code"

Each postal region is divided into postal sectors (each region consists of maximum 8 sectors). Sectors are numbered starting from 2 to 9; number (1) is excluded for government and exceptional services usage. Sectors are divided according to the following basis: The center of the region, which is usually its capital, is assigned the first number of sector numbers. Sectors to the south of the center are assigned even numbers. Sectors to the north of the center are assigned odd numbers. Upon dividing sectors, the following was taken into consideration: The borders of provinces' domains within any postal region. Terrain and geographical factors, such as: mountains, plains, valleys between provinces. Economic costs resulting from providing postal and logistic services. Population distribution and density inside the sectors.


Third Digit (Postal Branches): "The postal branch number is represented by the third digit of the postal code"

Each postal sector is divided into many postal branches, with maximum of 8 branches for each sector. Number (1) is excluded for governmental and exceptional services usage. Upon dividing branches, it was taken into consideration that their borders should be highways or main roads as much as possible. There are 3 distinct strategies when dividing Postal branches.


Fourth Digit (Postal Divisions): "The postal division number is represented by the fourth digit of the postal code"

Postal branches are divided into many divisions, each branch consists of maximum number of nine divisions. Divisions are almost equally divided. Areas of divisions may differ due to the following reasons:

1)Geographical and terrain factors between postal divisions. 2)Density of population in a given division. 3)Divisions of any branch are divided according to main roads and streets, and interconnecting streets, according to street categories. 4)Coding of postal divisions is based upon the nearest division to the axis of the division, where smaller numbers are assigned to postal divisions which are the closest to the axis lines. The numbers increase as we move far from the axis.


Fifth Digit (Postal Squares): "The postal square number is represented by the fifth digit of the postal code"

Each postal section is divided into squares. The area of each square should not be more than 4x4 km². Squares were divided according on the following basis:

1)Considering that no square should exceed 4x4 km². 2)Squares within low-density urban zones should be about 2x2 km². 3)Squares within high-density and populated urbban zones should be about 1x1 km². 4)Squares divisions are based on the network of main and side roads and streets, according to the nearest to the branch axis. The smallest number is assigned to square that are nearest to the axis. Square numbers increase ascendingly as we move far from the axis.


Submitted by Fares Alarabi - 7 years ago