PHPackages                             captn3m0/pincode - 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. captn3m0/pincode

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

captn3m0/pincode
================

A simple regex based validator for PIN codes in India

v3.0.0(8mo ago)8106MITJavaScriptCI passing

Since Feb 24Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/captn3m0/india-pincode-regex)[ Packagist](https://packagist.org/packages/captn3m0/pincode)[ GitHub Sponsors](https://github.com/captn3m0)[ Fund](https://ko-fi.com/captn3m0)[ RSS](/packages/captn3m0-pincode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

india-pincode-regex [![Packagist Version](https://camo.githubusercontent.com/3c64acb02b93bff1e7a7bb4670d471e70e0fe3b6073bf04baf30bed05f424b48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636170746e336d302f70696e636f64653f7374796c653d706c6173746963)](https://camo.githubusercontent.com/3c64acb02b93bff1e7a7bb4670d471e70e0fe3b6073bf04baf30bed05f424b48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636170746e336d302f70696e636f64653f7374796c653d706c6173746963) [![Tests](https://github.com/captn3m0/india-pincode-regex/actions/workflows/tests.yml/badge.svg)](https://github.com/captn3m0/india-pincode-regex/actions/workflows/tests.yml) [![npm](https://camo.githubusercontent.com/3e0b19f0dfe1cd18bab9728a8ea59faeebea84413deeebb1df5db49c8c4c25ec/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f70696e636f64652d76616c696461746f723f7374796c653d706c6173746963)](https://camo.githubusercontent.com/3e0b19f0dfe1cd18bab9728a8ea59faeebea84413deeebb1df5db49c8c4c25ec/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f70696e636f64652d76616c696461746f723f7374796c653d706c6173746963) [![GitHub package.json version](https://camo.githubusercontent.com/5408aa407aac2fa1f5a2e0c3f8303347e210318e11c4bbf727c3322b4605e1c9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7061636b6167652d6a736f6e2f762f636170746e336d302f696e6469612d70696e636f64652d72656765783f7374796c653d706c6173746963)](https://camo.githubusercontent.com/5408aa407aac2fa1f5a2e0c3f8303347e210318e11c4bbf727c3322b4605e1c9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7061636b6167652d6a736f6e2f762f636170746e336d302f696e6469612d70696e636f64652d72656765783f7374796c653d706c6173746963) [![GitHub](https://camo.githubusercontent.com/3894269fe8070e6e4227320da9e078b75c31db3c460688fb367755f5298cb078/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636170746e336d302f696e6469612d70696e636f64652d72656765783f7374796c653d706c6173746963)](https://camo.githubusercontent.com/3894269fe8070e6e4227320da9e078b75c31db3c460688fb367755f5298cb078/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636170746e336d302f696e6469612d70696e636f64652d72656765783f7374796c653d706c6173746963)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#india-pincode-regex-----)

Validate a [Postal Index Number](https://en.wikipedia.org/wiki/Postal_Index_Number) for India with a few regexes and zero false-positives. The regexes are available in `regex.txt`. There is one regex per area code (the first digit of the PIN, which goes from 1-8). Available as a package for Ruby, Python, Node.js, and browsers.

Why?
----

[](#why)

A simple `\d{6}` approach marks a lot of invalid pincodes as valid. Out of the 900000 possible combinations, only 19584 are valid pincodes in India. A simple example is `111111` which is an invalid pincode, but any simple 6 digit-check will pass it as a valid one.

Source
------

[](#source)

The source for the data is the ["All India Pincode Directory"](https://www.data.gov.in/resource/all-india-pincode-directory-till-last-month) dataset on data.gov.in. The last updated date for the dataset is currently 30th May 2019.

Usage
-----

[](#usage)

The `regex.txt` file is 32KB in size, so you can easily use it wherever you want, including browsers. If you are using any of the packages below, this is already delivered compressed. You can use the regex directly, or via a few helper methods.

Supported Language Versions
---------------------------

[](#supported-language-versions)

This project only supports [supported versions](https://endoflife.date) of various languages.

### PHP

[](#php)

The package is available on [`packagist`](https://packagist.org/packages/captn3m0/pincode).

To use the PHP package:

```
use PIN\Validator as P;
// validates a given pincode
// returns boolean
P::validate('110011'); // returns true;

// Searches for all valid pincodes in a given string.
// returns array(string)
P::search('bangalore 560029'); // returns ["560029"]
```

### Node.js

[](#nodejs)

The package is available on [`npm`](https://www.npmjs.com/package/pincode-validator).

To use the package:

```
const P = require('pincode-validator');
P.validate('110011'); // returns true
P.search('my pincode is 560029'); // returns ['560029']

// or directly use the regex in your code
P.exactRegex.match('560029')
"address with pincode (560029)".matchAll(P.regex)
```

Please see `tests/validate.js` for more examples.

Ruby
----

[](#ruby)

Add this line to your application's Gemfile:

```
gem 'pincode_validator'
```

And then execute:

```
$ bundle

```

Or install it yourself as:

```
$ gem install pincode_validator

```

```
require 'pincode_validator'

Pin::valid?('560029') # returns true
Pin::valid?('111111') # returns false

Pin::search('my pincode is 244713') # returns ['244713']
Pin::search('my pincode is 244713 or 560029') # returns ['244713', '560029']
```

### Browser

[](#browser)

To use it in the browser, download the `pincode-regex.js` file and include it in your browser. `Pincode` is available as a Global variable.

```

Pincode.validate("560029"); // returns true

```

You can use githack for directly using this in your code:  (Make sure you use the latest version). Please watch the repo to get notified of new releases.

Code of Conduct
---------------

[](#code-of-conduct)

Everyone interacting in the this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/captn3m0/outliner/blob/master/CODE_OF_CONDUCT.md).

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

[](#contributing)

- See [`CONTRIBUTING.md`](CONTRIBUTING.md) for some development details and contribution guidelines
- Pull requests are welcome for adding libraries in other languages (in the same repo). Python support is WIP, and I'd love to have support for other languages as well.
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

License
-------

[](#license)

Licensed under the [MIT License](https://nemo.mit-license.org/). See LICENSE file for details.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance61

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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

Every ~403 days

Recently: every ~504 days

Total

6

Last Release

249d ago

Major Versions

1.0.4 → v2.0.02023-07-10

v2.0.0 → v3.0.02025-09-02

### Community

Maintainers

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

---

Top Contributors

[![captn3m0](https://avatars.githubusercontent.com/u/584253?v=4)](https://github.com/captn3m0 "captn3m0 (59 commits)")

---

Tags

indianpm-packagephpphp-librarypinpincoderegexregexesvalidatorzero-dependencies

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/captn3m0-pincode/health.svg)

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

###  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)
