Regex for Indian PIN code (6 digits)

Indian postal PIN codes have six digits and never start with 0. Some people write them with a space after the third digit, such as 411 001, so this pattern allows both.

The pattern

/\b[1-9]\d{2}\s?\d{3}\b/g

The tester opens with this pattern and the examples below already loaded. Nothing you type is uploaded.

How it works

[1-9]
First digit, 1 to 9. It identifies the postal region.
\d{2}
Next two digits, completing the sub-region.
\s?
Optional space in the middle.
\d{3}
Last three digits, the delivery post office.

Examples

Matches

  • 324001
  • 411 001
  • 110001

Does not match

  • 012345
  • 32400
  • 3240012

Use it in JavaScript

const re = /\b[1-9]\d{2}\s?\d{3}\b/g;

// Find every match in a block of text
const found = text.match(re);

// Validate that a whole value matches (no stray characters around it)
const exact = new RegExp('^(?:' + re.source + ')$', re.flags.replace('g', ''));
const isValid = exact.test(value);

Limits and tips

  • A well-formed code can still be one that does not exist. Use a PIN-code lookup if you need to confirm it.
  • If you also store the space-free value, strip whitespace with replace(/\s/g, "") after validating.

Frequently asked questions

How many digits are in an Indian PIN code?

Six. The first digit is between 1 and 9.

Can a PIN code start with 0?

No. That is why the pattern begins with [1-9] rather than \d.