GithubHelp home page GithubHelp logo

za-id-validator-java's Introduction

ZA ID Number Validator Java Version

South African ID number validator written in Java. If you are looking for the PHP version go here: https://github.com/talifhani/za-id-validator

Usage

IDNumberParser idNumberParser = new IDNumberParser();
IDNumberData idNumberData = idNumberParser.parse("7801014800084");

System.out.println("isValid: " + idNumberData.isValid());
System.out.println("Date Of Birth: " + idNumberData.getBirthdate().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)));
System.out.println("Age: " + idNumberData.getAge());
System.out.println("Gender: " + idNumberData.getGender());
System.out.println("Citizenship: " + idNumberData.getCitizenShip());

Pivot Year

The first 2 digits of the South African ID number are the year. The problem with parsing this is we dont know if 19 means 2019 or 1919. So the parse by default assumes the ID Number belongs to someone not older than 100 years. So if this year is 2020, any years less than 20 will be considered from this century. e.g 15 and 19 will translate to 2015 and 2019 respectively. While 20, 25 will translate to 1920, 1925 respectively. This is the concept of a pivotYear. The pivotYear in the above cases defaulted to 1920. You can specify your own pivotYear using the setPivotYear method on the parser.

Example

IDNumberParser idNumberParser = new IDNumberParser();
IDNumberData idNumberData = idNumberParser.setPivotYear(Year.of(1940)).parse("4001014800084");//Also not a valid ID FYI

System.out.println("Date Of Birth: " + idNumberData.getBirthdate().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)));
//Date Of Birth: 01 January 1940

idNumberData = idNumberParser.parse("3901014800084");//Also not a valid ID FYI
System.out.println("Date Of Birth: " + idNumberData.getBirthdate().format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)));
//Date Of Birth: 01 January 2039

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

za-id-validator-java's People

Contributors

talifhani avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.