PHPackages                             zam3858/bemykad - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. zam3858/bemykad

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

zam3858/bemykad
===============

A PHP package to validate and extract information from Malaysian MyKad numbers.

1.0.3(1y ago)261MITPHPPHP ^8.1

Since Nov 4Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/zam3858/bemykad)[ Packagist](https://packagist.org/packages/zam3858/bemykad)[ RSS](/packages/zam3858-bemykad/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c5900f9a06d70a9c6414b640c234fb9cac625c78c5a1190f20385b9de368bf0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a616d333835382f62656d796b61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zam3858/bemykad) [![Fix PHP code style issues](https://github.com/zam3858/bemykad/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/zam3858/bemykad/actions/workflows/fix-php-code-style-issues.yml) [![PHPStan](https://github.com/zam3858/bemykad/actions/workflows/phpstan.yml/badge.svg)](https://github.com/zam3858/bemykad/actions/workflows/phpstan.yml) [![Tests](https://github.com/zam3858/bemykad/actions/workflows/run-tests.yml/badge.svg)](https://github.com/zam3858/bemykad/actions/workflows/run-tests.yml) [![Total Downloads](https://camo.githubusercontent.com/e17f55a97275a26721fcedc0f313f215d0754aa442053f48b798e4747f71b17b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a616d333835382f62656d796b61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zam3858/bemykad)

BeMyKad
=======

[](#bemykad)

`BeMyKad` is a PHP package for extracting information from Malaysian MyKad numbers. This package helps validate MyKad numbers, retrieve the date of birth, gender, and identify the state or country of birth from the MyKad number.

Installation
------------

[](#installation)

To install the package, use Composer:

```
composer require zam3858/bemykad
```

Usage
-----

[](#usage)

Below is a simple example of how to use the `BeMyKad` class.

### Basic Example

[](#basic-example)

```
use BeMyKad\BeMyKad;

$mykadNumber = "960101-14-1234";
$mykad = new BeMyKad($mykadNumber);

// Validate the MyKad number
if ($mykad->isValid()) {
    echo "MyKad is valid\n";

    // Get date of birth
    echo "Date of Birth: " . $mykad->getDateOfBirth() . "\n";

    // Get gender
    $gender = $mykad->getGender() === BeMyKad::MALE ? 'Male' : 'Female';
    echo "Gender: " . $gender . "\n";

    // Get state or country of birth
    echo "Place of Birth: " . $mykad->getState() . "\n";

    /**
     * Outputs
     * {
     * "mykad": "960101141234",
     * "formatted": "960101-14-1234",
     * "isValid": true,
     * "dateOfBirth": "1996-01-01",
     * "gender": "Male",
     * "state": "Johor"
     * }
     */
    echo $mykad;
} else {
    echo "Invalid MyKad number.";
}
```

### Methods

[](#methods)

- **`__construct(string $mykadNumber)`**: Initializes the `BeMyKad` instance with a MyKad number, automatically removing dashes for uniformity.
- **`isValid(): bool`**: Returns `true` if the MyKad number format and date of birth are valid.
- **`getDateOfBirth(): ?string`**: Returns the date of birth in `Y-m-d` format if valid, or `null` if invalid.
- **`getGender(): ?int`**: Returns `BeMyKad::MALE` or `BeMyKad::FEMALE` if valid, or `null` if invalid.
- **`getState(): ?string`**: Returns the place of birth (state or country) if valid. For codes that don't map to a specific place, returns `'Unknown'`.

### Validation Details

[](#validation-details)

- **Date of Birth Validation**: Ensures the date part of the MyKad number is valid by verifying it corresponds to a real calendar date and matches the expected century.
- **Format Validation**: Ensures the MyKad number is in one of two acceptable formats: `YYMMDD-SS-SSSS` or `YYMMDDSSSSSS`.

### Handling Unmapped Codes

[](#handling-unmapped-codes)

Certain codes, such as `'99'`, represent categories rather than specific locations and return `'Unknown'`. This ensures a consistent output for codes that indicate unspecified regions.

### Exceptions

[](#exceptions)

The `BeMyKad` class does not throw exceptions by default for invalid MyKad numbers. Instead, validation methods (`isValid`, `getDateOfBirth`, `getGender`, `getState`) return `null` or `false` when the MyKad number is invalid.

Additional Class: `BirthCountry`
--------------------------------

[](#additional-class-birthcountry)

The `BirthCountry` class contains the mappings for MyKad place-of-birth codes to their respective locations. You can retrieve the mapped location directly using the following method:

- **`getPlaceOfBirth(string $code): string`**: Returns the place of birth corresponding to the provided code. If the code is not recognized, it returns `'Unknown'`.

### Example Usage of `BirthCountry`

[](#example-usage-of-birthcountry)

```
use BeMyKad\BirthCountry;

echo BirthCountry::getPlaceOfBirth('10'); // Outputs: "Selangor"
echo BirthCountry::getPlaceOfBirth('99'); // Outputs: "Unknown"
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

We welcome contributions! Please see [CONTRIBUTING](CONTRIBUTING.md) for details on how to get involved.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover any security issues, please review our [security policy](../../security/policy) for reporting vulnerabilities.

Credits
-------

[](#credits)

- [Hizam Mohd](https://github.com/zam3858)
- [Nasrul Hazim](https://github.com/nasrulhazim)

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT License](LICENSE.md).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance47

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

550d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.4

1.0.3PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/404ad7ef02d3bf3b135fbccf818de92ea7d3718afe4a926b9f1ec25efeb47090?d=identicon)[zam3858](/maintainers/zam3858)

---

Top Contributors

[![nasrulhazim](https://avatars.githubusercontent.com/u/10341422?v=4)](https://github.com/nasrulhazim "nasrulhazim (14 commits)")[![zam3858](https://avatars.githubusercontent.com/u/99651?v=4)](https://github.com/zam3858 "zam3858 (14 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/zam3858-bemykad/health.svg)

```
[![Health](https://phpackages.com/badges/zam3858-bemykad/health.svg)](https://phpackages.com/packages/zam3858-bemykad)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
