-
Notifications
You must be signed in to change notification settings - Fork 0
nationalid
Validate Iranian national numbers (code-e Melli) and resolve the issuing city and province.
import "github.com/amiranmanesh/go-persian-tools/nationalid"nationalid.Validate("0067749828") // true
nationalid.Validate("0684159415") // falseThe code must be exactly ten ASCII digits and pass the official check-digit
algorithm. Codes made of a single repeated digit (0000000000, 2222222222
and so on) are rejected even when the checksum happens to work out — with the
documented exception of 1111111111, which is a genuine issued code.
Persian digits are not accepted here; normalize first if your input may carry them:
nationalid.Validate(digit.ToEnglishDigits(input))The first three digits identify the district where the birth certificate was issued:
place := nationalid.GetPlaceByIranNationalID("0499370899")
place.City // شهرری
place.Province // تهران
place.Codes // []string{"048", "049"}type Place struct {
Codes []string // every prefix that maps to this city
City string
Province string
}A zero Place comes back when the id is not ten characters long or its prefix
matches no known district. The lookup is by prefix only — it does not
validate the checksum, so call Validate too if you need both.
The table holds 477 districts across 31 province entries (30 provinces plus
امور خارجه, used for certificates issued abroad).
Because the code records where a certificate was issued, it reflects the country's divisions at that time. Karaj and Nazarabad, for instance, sit under Tehran rather than Alborz, which was split off in 2010.
Corrections applied in v1.1.0, where six rows had been appended to the table under Isfahan's province code:
| District | Was | Now |
|---|---|---|
| زنجان، ابهر، خرمدره | اصفهان | زنجان |
| مرند، ملکان، میانه | اصفهان | آذربایجان شرقی |
See Data sources for how these were verified.
Packages
Project