Regex for Indian PIN Code Validation — 6-Digit Postal Codes

India Post's Postal Index Number (PIN) system uses a 6-digit code to route mail to one of over 19,000 delivery post offices. Any address form, e-commerce checkout, or logistics app built for Indian users needs to validate this field reliably. This guide covers the PIN code structure, a solid regex pattern, and implementation examples in JavaScript and Python.

Understanding the PIN code format

An Indian PIN code is always 6 digits, and each digit position carries meaning:

  • 1st digit — the postal zone (1 through 9; there is no zone 0).
  • 2nd digit — the sub-zone within that region.
  • 3rd digit — the sorting district within the sub-zone.
  • Last 3 digits — identify the specific post office or delivery point.

An example valid PIN code is 110001 (Connaught Place, New Delhi).

The PIN code regex pattern

^[1-9][0-9]{5}$

This requires exactly 6 digits total, with the first digit restricted to 1-9 so codes like 012345 are correctly rejected.

JavaScript example

function isValidPinCode(pin) {
  const pinRegex = /^[1-9][0-9]{5}$/;
  return pinRegex.test(pin.trim());
}

console.log(isValidPinCode("110001")); // true
console.log(isValidPinCode("012345")); // false - starts with 0
console.log(isValidPinCode("11000"));  // false - only 5 digits

Python example

import re

PINCODE_REGEX = re.compile(r"^[1-9][0-9]{5}$")

def is_valid_pincode(pin: str) -> bool:
    return bool(PINCODE_REGEX.match(pin.strip()))

print(is_valid_pincode("560001"))  # True - Bengaluru GPO
print(is_valid_pincode("56000"))   # False - only 5 digits

HTML input example

For a checkout or address form, you can pair the pattern attribute with numeric input restrictions to guide mobile keyboards and give instant browser-level feedback:

<input
  type="text"
  inputMode="numeric"
  maxLength={6}
  pattern="[1-9][0-9]{5}"
  placeholder="e.g. 400001"
  title="Enter a valid 6-digit PIN code"
/>

Common mistakes to avoid

  • Allowing the first digit to be 0 — no Indian postal zone uses 0 as the leading digit.
  • Accepting PIN codes with a space in the middle, like 110 001. If you want to support that display format, strip spaces before validating rather than baking them into the regex.
  • Assuming a syntactically valid PIN code exists in the India Post database. For critical delivery flows, verify against a real PIN code dataset or lookup API.

Frequently Asked Questions

What is the regex for validating an Indian PIN code?

A reliable pattern is ^[1-9][0-9]{5}$. It requires exactly 6 digits where the first digit is between 1 and 9, since Indian PIN codes never start with 0.

Why can't an Indian PIN code start with zero?

The first digit of a PIN code represents one of nine postal zones in India, numbered 1 through 9 (zone 0 is not used). The second digit represents the sub-zone, and the following digits identify the specific sorting district and delivery office.

Should I use regex alone to validate a delivery address PIN code?

Regex confirms the PIN code is correctly formatted but not that it is a real, currently active code. For shipping or logistics forms, pair regex validation with a PIN code lookup API or a local dataset of valid Indian PIN codes to also auto-fill city and state.

Try the Free AI Regex Generator

Need a regex for another address field or custom validation rule? Describe it in plain English and get a tested pattern instantly with Dev Brains AI's free AI Regex Generator.

Related articles