Iranian Mobile Numbers in Forms: Normalization That Saves You Trouble Later
0912…, 912…, +98912… and 0098912… are all the same number. If you store them raw, your SMS messages won't reach half of them.
Users write their mobile number in all sorts of formats, and every one of them is correct from the user's point of view. The trouble starts when you want to send an SMS or compare two records.
The formats that actually come in
09121234567: the most common9121234567: without the leading zero+989121234567and00989121234567: with the country code (+98 for Iran)0912 123 4567and0912-123-4567: with spaces or hyphens۰۹۱۲۱۲۳۴۵۶۷: in Persian digits
All of these are the same number. The form should accept every one of them and store a single canonical format.
The normalization rule
- Persian and Arabic digits → Latin
- Strip everything except digits and the plus sign
- A leading
+98,0098or98→ removed and replaced with0 - If it starts with
9and is ten digits long → prepend0 - The result must be exactly 11 digits and start with
09
Why the leading zero matters
If you define the field as a "number," 09121234567 becomes 9121234567, and the same thing happens in Excel. Then when you hand the file to your SMS gateway, some of the numbers are ten digits long and get rejected. A mobile number is text, not a number.
Prefix validation
Not every number that starts with 09 is valid. The real prefixes of Iran's mobile operators are limited (0912, 0913, 0935, 0901, …). If you want to be strict, you can check the prefix too, but be careful: operators add new prefixes, and an outdated list will reject real numbers. Usually "11 digits, starting with 09" is a good balance.
When the number is the identity key
If you want each person to respond only once and you've made the mobile number the key, normalization is no longer optional. Without it, the same person types +98912… instead of 0912…, responds again, and you have two records you think belong to two different people.