lanka-validations - v2.1.0
    Preparing search index...

    Function parseNic

    • Parses a Sri Lankan National Identity Card number. Returns structured NicInfo if valid, or null if invalid.

      Parameters

      • rawNic: unknown

        NIC number, old or new format. Strings and finite numbers are accepted; other types return a failure without throwing.

      • Optionaloptions: NicOptions

        Optional { referenceDate } used for age and future-date checks. Defaults to today.

      Returns NicInfo | null

      Decoded details (date of birth, age, gender, both formats), or null if the NIC is invalid.

      parseNic('921234567V')?.dobString; // '1992-05-02'
      parseNic('921234567V')?.gender; // 'male'
      parseNic('921234567V')?.newNic; // '199212304567'
      parseNic('invalid'); // null