Skip to content

Commit

Permalink
feat: added validators for PAN, TAN, UAN, IFSC and ESIC
Browse files Browse the repository at this point in the history
  • Loading branch information
mastermunj committed Apr 27, 2020
1 parent da31838 commit ac7626e
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 0 deletions.
143 changes: 143 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Format Utilities

## Introduction

Utilities for validating various formats of Indian system codes like Mobile, PAN, AADHAR, UID and more!

## Installation

```js
npm install format-utils --save
```

## Usage

```js
const { Validator } = require('format-utils');
```
OR
```js
import { Validator } from 'format-utils';
```

## Available Validators

### Mobile

A mobile is a 10 digit numerical code starting with either 6, 7, 8, 9.

```js
let isValid = Validator.mobile('9876543210');
// isValid = true

isValid = Validator.mobile('5678943210');
// isValid = false
```

### PIN (Postal Index Number)

A pincode is a 6 digit numeric code used by Indian Post.

#### Format
* The first character is a number from `1` to `9`.
* The second to sixth characters are numberical sequence from `00000` to `99999`.

```js
let isValid = Validator.pincode('400001');
// isValid = true

isValid = Validator.pincode('0123456');
// isValid = false
```

### PAN (Permanent Account Number)

A PAN is a 10 digit alphanumeric code issued by Income Tax Department of India.

#### Format
* The first three characters are alphabetic series running from `AAA` to `ZZZ`.
* The fourth character represents the status of the PAN holder.
* `P` stands for Individual
* `C` stands for Company
* `H` stands for Hindu Undivided Family (HUF)
* `A` stands for Association of Persons (AOP)
* `B` stands for Body of Individuals (BOI)
* `G` stands for Government Agency
* `J` stands for Artificial Juridical Person
* `L` stands for Local Authority
* `F` stands for Firm/ Limited Liability Partnership
* `T` stands for Trust
* The fifth character represents the first character of the PAN holder's last name/surname in case of an individual. In case of non-individual PAN holders fifth character represents the first character of PAN holder's name.
* The sixth to ninth characters are sequential numbers running from `0001` to `9999`.
* The tenth character is an alphabetic check digit.

Visit [this](https://www.incometaxindia.gov.in/Forms/tps/1.Permanent%20Account%20Number%20(PAN).pdf) to know more about PAN.

```js
let isValid = Validator.pan('ALWPG5809L');
// isValid = true

isValid = Validator.pan('ABAB12345Y');
// isValid = false
```

### TAN (Tax Deduction and Collection Account Number)

A TAN is a 10 digit alphanumeric code.

#### Format
* The first four characters are alphabetic series running from `AAAA` to `ZZZZ`.
* The fifth to ninth characters are sequential numbers running from `00001` to `99999`.
* The tenth character is an alphabetic character.

```js
let isValid = Validator.tan('RAJA99999B');
// isValid = true

isValid = Validator.tan('RAJA999991');
// isValid = false
```

### UAN (Universal Account Number)

A UAN is a 12 digit numberic code that is issued to member of the Employees’ Provident Fund Organisation (EPFO).

```js
let isValid = Validator.uan('987654321098');
// isValid = true

isValid = Validator.uan('A98765432109');
// isValid = false
```

### IFSC (Indian Financial System Code)

A IFSC is a 11 digit alphanumberic code that is issued to member of the Employees’ Provident Fund Organisation (EPFO).

#### Format
* The first four characters are alphabets that denote the bank name.
* The fifth character is numerical zero (`0`).
* The sixth to eleventh characters are numerical code that denote the branch name.


```js
let isValid = Validator.ifsc('SBIN0011569');
// isValid = true

isValid = Validator.ifsc('BK1D0006046');
// isValid = false
```

### ESIC (Employee State Insurance Corporation) Code

A ESIC code is a 17 digit numerical code that is issued by Employee State Insurance Corporation.

```js
let isValid = Validator.esic('12345678901234567');
// isValid = true

isValid = Validator.esic('1234567890123456');
// isValid = false
```


75 changes: 75 additions & 0 deletions __tests__/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,78 @@ describe('Pincode', () => {
expect(Validator.pincode(value)).toBe(expected);
});
});

describe('PAN', () => {
const tests: [string, boolean][] = [
['ALWPG5809L', true],
['alwpg5809l', true],
['ABAB12345Y', false],
['abab12345y', false],
];
test.each(tests)(`Check %s => %s`, (value, expected) => {
expect(Validator.pan(value)).toBe(expected);
});
});

describe('TAN', () => {
const tests: [string, boolean][] = [
['RAJA99999B', true],
['AAAA99999A', true],
['BLRW39567H', true],
['blrw39567h', true],

['RAJA999991', false],
['RAJA9999WB', false],
['R2JA9999WB', false],
['R2JA9999B', false],
['R2JA9999WB1', false],
];
test.each(tests)(`Check %s => %s`, (value, expected) => {
expect(Validator.tan(value)).toBe(expected);
});
});

describe('UAN', () => {
const tests: [string, boolean][] = [
['987654321098', true],
['123456789012', true],

['98765432101', false],
['9876543210987', false],
['A98765432109', false],
['98765432109A', false],
];
test.each(tests)(`Check %s => %s`, (value, expected) => {
expect(Validator.uan(value)).toBe(expected);
});
});

describe('IFSC', () => {
const tests: [string, boolean][] = [
['SBIN0011569', true],
['BKID0006046', true],
['BKID000604D', true],

['BKID000604', false],
['BKID1006046', false],
['BK1D0006046', false],
['BKID00060461', false],
['BKID0006046D', false],
];
test.each(tests)(`Check %s => %s`, (value, expected) => {
expect(Validator.ifsc(value)).toBe(expected);
});
});

describe('ESIC', () => {
const tests: [string, boolean][] = [
['12345678901234567', true],

['123456789012345678', false],
['1234567890123456', false],
['A2345678901234567', false],
];
test.each(tests)(`Check %s => %s`, (value, expected) => {
expect(Validator.esic(value)).toBe(expected);
});
});
20 changes: 20 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@ export class Validator {
static pincode(value: string | number): boolean {
return /^[1-9]\d{5}$/.test(value as string);
}

static pan(value: string): boolean {
return /^[A-Z]{3}[PCHABGJLFTE][A-Z]\d{4}[A-Z]$/i.test(value);
}

static tan(value: string): boolean {
return /^[A-Z]{4}\d{5}[A-Z]$/i.test(value);
}

static uan(value: string): boolean {
return /^\d{12}$/.test(value);
}

static ifsc(value: string): boolean {
return /^[A-Z]{4}0[A-Z0-9]{6}$/i.test(value);
}

static esic(value: string): boolean {
return /^\d{17}$/.test(value);
}
}

0 comments on commit ac7626e

Please sign in to comment.