The Government Multi-Purpose Smart Card Project (MPSC) or MyKad is part of the Multimedia Super Corridor (MSC Malaysia) initiative.
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.
You can install the package via composer:
composer require akukoder/mykad-validator
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')) {
}
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)) {
}
composer test
The MIT License (MIT).