PHPackages                             jmbg-labs/jmbg - 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. jmbg-labs/jmbg

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

jmbg-labs/jmbg
==============

Validate Serbian unique master citizen number (JMBG - Jedinstveni Matični Broj Građana)

v1.0.0(1mo ago)01↓100%MITPHPPHP ^8.1

Since Mar 16Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

JMBG PHP Library
================

[](#jmbg-php-library)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/d6aac44f81cb2e6f4e71f098a1cb4a71992f24f7bfb424f6670db8313c9a855c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e312d626c7565)](https://www.php.net/)

A PHP library for validating and parsing Serbian unique master citizen numbers (JMBG - Jedinstveni Matični Broj Građana).

Features
--------

[](#features)

- ✅ Validate JMBG numbers with comprehensive checks
- ✅ Extract birth date, region, and gender information
- ✅ Support for all Serbian regions
- ✅ Calculate age from JMBG
- ✅ Type-safe with PHP 8.1+ features
- ✅ Fully tested with PHPUnit
- ✅ PSR-12 compliant code

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

[](#installation)

Install via Composer:

```
composer require jmbg-labs/jmbg
```

Usage
-----

[](#usage)

### Basic Validation

[](#basic-validation)

```
use JmbgLabs\Jmbg\Jmbg;

// Quick validation
if (Jmbg::valid('0101000710009')) {
    echo "Valid JMBG";
}

// Parse and validate
try {
    $jmbg = Jmbg::parse('0101000710009');
    echo "Valid JMBG: " . $jmbg->format();
} catch (JmbgException $e) {
    echo "Invalid JMBG: " . $e->getMessage();
}
```

### Extract Information

[](#extract-information)

```
use JmbgLabs\Jmbg\Jmbg;

$jmbg = new Jmbg('0101000710009');

// Get birth date
$date = $jmbg->getDate(); // DateTime object
echo $date->format('Y-m-d'); // 2000-01-01

// Get age
echo $jmbg->getAge(); // e.g., 26

// Check gender
if ($jmbg->isMale()) {
    echo "Male";
}

if ($jmbg->isFemale()) {
    echo "Female";
}

// Access individual parts
echo $jmbg->day;           // 1
echo $jmbg->month;         // 1
echo $jmbg->year;          // 2000
echo $jmbg->region;        // 71
echo $jmbg->region_text;   // "Belgrade"
echo $jmbg->country;       // "Serbia"
echo $jmbg->unique;        // 0
echo $jmbg->checksum;      // 9
```

### Using Magic Methods

[](#using-magic-methods)

```
$jmbg = new Jmbg('1505995800002');

// String conversion
echo (string)$jmbg; // "1505995800002"
echo $jmbg->format(); // "1505995800002"

// Property access
echo $jmbg->original;        // "1505995800002"
echo $jmbg->day_original;    // "15"
echo $jmbg->month_original;  // "05"
echo $jmbg->year_original;   // "995"
echo $jmbg->region_original; // "80"
echo $jmbg->unique_original; // "000"

// Check property existence
if (isset($jmbg->region_text)) {
    echo $jmbg->region_text; // "Novi Sad"
}
```

JMBG Format
-----------

[](#jmbg-format)

JMBG consists of 13 digits: `DDMMYYYRRBBBC`

- **DD** - Day of birth (01-31)
- **MM** - Month of birth (01-12)
- **YYY** - Year of birth (last 3 digits)
- **RR** - Region code
- **BBB** - Unique number (000-499 for males, 500-999 for females)
- **C** - Checksum digit

### Supported Regions

[](#supported-regions)

The library supports all Serbian and ex-Yugoslav regions including (beware: ex-Yugoslav regions codes may have changed since the breakup):

- **Serbia** (71-79): Belgrade, Kragujevac, Niš, etc.
- **Serbia/Vojvodina** (80-89): Novi Sad, Subotica, Pančevo, etc.
- **Serbia/Kosovo** (91-96): Priština, Peć, Prizren, etc.
- **Bosnia and Herzegovina** (10-19)
- **Montenegro** (21-29)
- **Croatia** (30-39)
- **Macedonia** (41-49)
- **Slovenia** (50)

Validation Rules
----------------

[](#validation-rules)

The library performs comprehensive validation:

1. **Length check** - Must be exactly 13 digits
2. **Format check** - Must contain only numeric characters
3. **Date validation** - Birth date must be valid (including leap year support)
4. **Region validation** - Region code must exist in the registry
5. **Checksum validation** - Modulo 11 algorithm verification

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Run all tests
composer test

# Run tests with coverage
composer test-coverage
```

### Code Style

[](#code-style)

```
# Check code style
composer cs

# Fix code style issues
composer cs-fix
```

Requirements
------------

[](#requirements)

- PHP ^8.1
- No external dependencies (for production use)

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

[](#contributing)

Contributions are welcome! Please ensure:

1. All tests pass (`composer test`)
2. Code follows PSR-12 standards (`composer cs`)
3. Add tests for new features
4. Update documentation as needed

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Credits
-------

[](#credits)

Developed by [JMBG Labs](https://github.com/jmbg-labs)

Support
-------

[](#support)

- 🐛 [Report Issues](https://github.com/jmbg-labs/php/issues)
- 📖 [Source Code](https://github.com/jmbg-labs/php)

Examples
--------

[](#examples)

### Validate Multiple JMBGs

[](#validate-multiple-jmbgs)

```
$jmbgs = ['0710003730015', '1705978730032', 'invalid'];

foreach ($jmbgs as $jmbgString) {
    if (Jmbg::valid($jmbgString)) {
        $jmbg = Jmbg::parse($jmbgString);
        echo sprintf(
            "%s - Born: %s, Region: %s, Gender: %s\n",
            $jmbg->format(),
            $jmbg->getDate()->format('Y-m-d'),
            $jmbg->region_text,
            $jmbg->isMale() ? 'Male' : 'Female'
        );
    } else {
        echo "$jmbgString - Invalid\n";
    }
}
```

### Age Calculation

[](#age-calculation)

```
$jmbg = new Jmbg('0710003730015');
$age = $jmbg->getAge();

if ($age >= 18) {
    echo "Adult";
} else {
    echo "Minor";
}
```

### Error Handling

[](#error-handling)

```
use JmbgLabs\Jmbg\Jmbg;
use JmbgLabs\Jmbg\JmbgException;

try {
    $jmbg = new Jmbg('1234567890123');
} catch (JmbgException $e) {
    // Handle specific validation errors
    echo "Validation failed: " . $e->getMessage();
    // Possible messages:
    // - "Input string must have 13 digits."
    // - "JMBG string must have 13 digits."
    // - "Date '...' is not valid."
    // - "Region '...' is not valid for Serbian JMBG."
    // - "Checksum is not valid."
}
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance89

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

56d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2c444509cb608bb6354a35ca129d780fa75a4c4dbc79a4a998a69f42f122919?d=identicon)[dusanvelickovic](/maintainers/dusanvelickovic)

---

Top Contributors

[![dusanvelickovic](https://avatars.githubusercontent.com/u/73674795?v=4)](https://github.com/dusanvelickovic "dusanvelickovic (9 commits)")

---

Tags

citizen-ididentifierjmbgjmbg-validationnational-idphpserbiavalidationvalidatorvalidationidentifiernational idserbiajmbgcitizen-number

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jmbg-labs-jmbg/health.svg)

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[vlucas/valitron

Simple, elegant, stand-alone validation library with NO dependencies

1.6k4.4M128](/packages/vlucas-valitron)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M30](/packages/wixel-gump)

PHPackages © 2026

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