REGEXVAULT
Localization/Postal Codes
ReDoS Checked

Indian PIN Code Regex for Java

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

All five implementations are free. Switch engines without signing in.

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching indian pin code, ported and verified for Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

Java
// Indian PIN Code
// ReDoS-checked | RegexVault — Localization > Postal Codes

import java.util.regex.Pattern;

public class IndianPinCodeValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^[1-9][0-9]{5}$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("110001")); // true
    }
}

Test Cases

Matches (Valid)
Rejects (Invalid)
11000101001
40000110000
7000011100001
60000111000A
5000010

When to use this pattern

This pattern is drawn from the Localization > Postal Codes category and has been checked for ReDoS risk. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Not all 6-digit combinations starting with 1-9 are valid PIN codes — validate against India Post's postal database for confirmed delivery. Military Field Post Offices (FPO) use codes in the 900xxx range.

Technical Notes

Indian PIN code structure: first digit = postal zone (1-9, excludes 0), second digit = sub-zone, third digit = sorting district, last 3 digits = individual post office. Delhi is 110xxx, Mumbai is 400xxx.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Submissions join the review queue after automated validation.

Submit a Pattern