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 common
  • 9121234567: without the leading zero
  • +989121234567 and 00989121234567: with the country code (+98 for Iran)
  • 0912 123 4567 and 0912-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

  1. Persian and Arabic digits → Latin
  2. Strip everything except digits and the plus sign
  3. A leading +98, 0098 or 98 → removed and replaced with 0
  4. If it starts with 9 and is ten digits long → prepend 0
  5. 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.

Tags:mobile numbervalidationSMSIran