PatternRegex

Validate an Indian PIN code

Confirm a postal PIN code field holds exactly six digits and doesn't start with a zero, matching how India's postal zones are numbered.

Last updated

Pattern
^[1-9]\d{5}$
Open in Regex Tester & Builder

Matches

  • 110001
  • 400001
  • 560001

Doesn’t match

  • 012345
  • 12345
  • 1100011

Why it’s written this way

India's PIN codes are always six digits, and the first digit identifies one of nine postal zones numbered 1 through 9 — zone 0 was never assigned, so [1-9] for the leading digit followed by \d{5} for the rest both matches the real numbering scheme and rejects an obviously wrong leading zero.

Anchoring with ^ and $ keeps the check to exactly six characters — a seven-digit string, or a PIN code with a stray trailing space, won't slip through.

Edge cases to know

  • →It confirms the shape of a PIN code, not that the code is actually assigned to a real post office — that lookup needs India Post's own data, not a regex.
  • →It doesn't distinguish delivery post offices from ones that exist only for sorting, so a shape-valid PIN may still not accept parcel delivery.
  • →Whitespace or punctuation anywhere in the string fails the match — trim the input before testing it.

Part by part

^[1-9]
A required first digit between 1 and 9. No Indian PIN code begins with zero, so this single restriction rejects a common typo.
\d{5}$
Five further digits to make six in total, anchored to the end so nothing trails the code.

Common mistakes

  • ^\d{6}$

    Accepts 000000 and every other code beginning with zero, none of which exist. The leading-digit restriction is cheap and removes a whole class of invalid input.

    ^[1-9]\d{5}$
  • ^[1-9]\d{5}

    Without the end anchor a longer number passes as long as its first six digits are valid, so a phone number entered into the wrong field is accepted.

  • ^[1-9]\d{2}\s?\d{3}$

    Allowing an internal space matches the spaced form people sometimes write, but then the stored value varies by how it was typed. Strip whitespace before validating instead of accepting both shapes.

Questions

What do the digits mean?

The first indicates the postal zone, the first two together the sub-zone, the first three the sorting district, and the last three the specific post office. That structure is why the leading zero is impossible.

Does a match mean the code exists?

No. It confirms the format, not that any post office has that number. India Post publishes the current list, and it changes — validate against that data if delivery depends on it.

Should I use the PIN code to infer the state?

Only as a hint to prefill a form. The first digit narrows the region but boundaries do not follow state lines exactly, so let the user correct it rather than treating the inference as authoritative.

How should I store it?

As a string, never as a number. Numeric storage is fine here because there are no leading zeros, but keeping it as text avoids arithmetic being applied by accident and matches how every other address field is handled.

Do PIN codes ever change?

New ones are added as areas develop and post offices open or close, though existing codes are rarely withdrawn. That makes a hard-coded list a maintenance liability — validate the format with this pattern and check membership against data you can refresh.

Related in Patterns