akukoder / mykad-validator
A library for validating MyKad or MyKid format
Installs: 1 843
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.3
Requires (Dev)
- orchestra/testbench: ^5.2
- phpunit/phpunit: ^9.1
This package is auto-updated.
Last update: 2024-10-19 21:52:21 UTC
README
About MyKad
The Government Multi-Purpose Smart Card Project (MPSC) or MyKad is part of the Multimedia Super Corridor (MSC Malaysia) initiative.
Introduction
One of the most annoying thing when dealing with user records is when they entered wrong MyKad/MyKid number. This package helps reduce the burden to deal with invalid input by users.
This package will validate MyKad/MyKid number to make sure:
- Contains numbers only
- Valid length
- Valid date of birth
- Valid state/country code
Note:
Any other unnecessary characters from the input will be removed, including dashes.
Installation
You can install the package via composer:
composer require akukoder/mykad-validator
Usage
use AkuKoder\MyKadValidator\Validator; $validator = new Validator; // This will return false if ($validator->validate('982404-06-5883')) { } // This will return false if ($validator->validate('982404-06-83')) { } // This will return false if ($validator->validate('980404-00-5335')) { } // This will return false if ($validator->validate('9804AA-00-5335')) { } // This will return true if ($validator->validate('980404-06-5335')) { }
Get exception on errors
use AkuKoder\MyKadValidator\Validator; $validator = new Validator; // This will throw \AkuKoder\MyKadValidator\Exceptions\InvalidDateException if ($validator->validate('982404-06-5883', true)) { } // This will throw \AkuKoder\MyKadValidator\Exceptions\InvalidLengthException if ($validator->validate('982404-06-83', true)) { } // This will throw \AkuKoder\MyKadValidator\Exceptions\InvalidCodeException if ($validator->validate('980404-00-5335', true)) { } // This will throw \AkuKoder\MyKadValidator\Exceptions\InvalidCharacterException if ($validator->validate('9804AA-00-5335', true)) { }
Testing
composer test
Reference
License
The MIT License (MIT).