Function phoneNumberNormalizer

  • Normalize a phone number to a standard format based on the provided token. This function is related to the phoneNumberValidator function to detect that the mobile number is valid or not

    Parameters

    • phoneNumber: string
    • token: "0" | "+98"

      can be either +98 or 0

    Returns string

    String | never

    phoneNumberNormalizer("+989022002580", "0"); // 09022002580
    phoneNumberNormalizer("989022002580", "0"); // 09022002580
    phoneNumberNormalizer("09022002580", "0"); // 09022002580
    phoneNumberNormalizer("09022002580", "+98"); //+989022002580
    phoneNumberNormalizer("09802002580", "0"); // Error : this is not valid phone number