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)
/^(\+98|98|0098|0)?9(\d{2})\d{7}$/ and confirms the 3-digit operator prefix is in the known list.
The exported name isisPhoneNumberValid. There is novalidatePhoneNumber.
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.
OperatorModel | null. The operator name is result.operator.name — the function does not return a bare string.
There is nogetPhoneOperatorfunction. UsephoneNumberDetail(...)?.operator?.nameif you want just the name.
getPhoneNumberPrefix(mobile)
Returns the 4-digit prefix (including the leading 9):
Types
Recommended pipeline
Pitfalls
- Mobile only. Landlines (
021...,031..., …) all fail validation. phoneNumberDetailreturns an object, not a string. Older docs claim otherwise.phoneNumberNormalizerthrows on invalid input — wrap intry/catchorisPhoneNumberValidfirst.- 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