Skip to main content
Validate Iranian mobile numbers, switch between 0 and +98 formats, and detect the carrier (همراه اول, ایرانسل, …) plus province coverage from the 3-digit operator prefix.
This module validates mobile numbers only. Landline validation is not supported.

Functions

isPhoneNumberValid(mobile)

Internally checks /^(\+98|98|0098|0)?9(\d{2})\d{7}$/ and confirms the 3-digit operator prefix is in the known list.
The exported name is isPhoneNumberValid. There is no validatePhoneNumber.

phoneNumberNormalizer(phoneNumber, token)

Convert between 0 and +98 representations. Throws on invalid input.
token is exactly "0" | "+98" — no other formats.

phoneNumberDetail(mobile)

Look up operator + province coverage by the 3-digit operator prefix.
Returns OperatorModel | null. The operator name is result.operator.name — the function does not return a bare string.
There is no getPhoneOperator function. Use phoneNumberDetail(...)?.operator?.name if you want just the name.

getPhoneNumberPrefix(mobile)

Returns the 4-digit prefix (including the leading 9):
Useful for grouping numbers in reports.

Types

Pitfalls

  • Mobile only. Landlines (021..., 031..., …) all fail validation.
  • phoneNumberDetail returns an object, not a string. Older docs claim otherwise.
  • phoneNumberNormalizer throws on invalid input — wrap in try/catch or isPhoneNumberValid first.
  • Persian/Arabic digit input is not normalized. Pre-convert with autoConvertDigitsToEN.

Source

src/modules/phoneNumber/ (validator.ts, detail.ts, normalizer.ts, utils.ts) · Tests: test/phoneNumber.spec.ts