Persian Tools - v4.0.4
    Preparing search index...

    Function verifyIranianNationalId

    • Validates Iranian National ID (Code Melli) using the official checksum algorithm.

      Logic:

      1. Check length: If it's fewer than 8 digits, reject.
      2. Check if parseInt(code) is 0: If the entire code is "0..." (e.g., "00000000"), reject.
      3. Zero-pad the code to length 10 using four leading zeros and substring:
        • code = ('0000' + code).substr(length + 4 - 10)
        • This ensures the final string is exactly 10 characters, padded on the left.
      4. Check the 6 middle digits (index 3..8):
        • If parseInt(code.substr(3, 6)) is 0, reject.
      5. Compute the checksum:
        • Extract the last digit (c = parseInt(code.substr(9, 1))).
        • Multiply each of the first 9 digits by descending weights (10 down to 2).
        • Take the sum modulo 11.
        • Compare the result to the check digit (c).
      6. Return a boolean indicating if it passes.

      Parameters

      • nationalId: string | number

        The national ID as a string or number.

      • options: VerifyIranianNationalIdOptions = ...

        An optional configuration object.

        • OptionalcheckPrefix?: boolean

          Check the first 3 digits of the national ID against a predefined list of valid city codes.

          true
          

      Returns boolean

      A boolean indicating whether the ID is valid.