JSPM

south-africa-national-id-validation

3.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 83
  • Score
    100M100P100Q87630F
  • License MIT

Checks the South Africa National ID input is valid and allows you to return specific error messages

Package Exports

  • south-africa-national-id-validation

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (south-africa-national-id-validation) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

πŸ‡ΏπŸ‡¦ South Africa National ID Validation

npm npm Build Status Coverage Status GitHub

Checks the National ID input:

  • is valid (regex)
    • correct format
    • correct citizenship
    • correct number of digits
    • not blank
  • passes checksum
  • has a correct date
  • is above a minimum age (optional)

Usage

Grab from NPM / Yarn

npm i south-africa-national-id-validation
yarn add south-africa-national-id-validation
import verifyNationalIdNumber from 'south-africa-national-id-validation'

verifyNationalIdNumber({
    number //(string) the number to check
    minAge //(number) minimum allowed age
    errorMessages: {
        format //(string) error to display when format check fails
        date //(string) error to display when date check fails
        age //(string) error to display when age check fails
        checksum //(string) error to display when checksum check fails
    }
})

Check out the tests for specific use case examples


Based off the westercape docs

Inspired by valid-south-african-id

TODO

  • Consider using date-fns/toDate helper for date validation once 2.0 is released