Contact
India PIN Code Regex
India Post uses six-digit Postal Index Numbers, often called PIN codes, where the first digit indicates a postal region and never starts with zero. Some people write the code with a space after the first three digits, so this pattern accepts both 110001 and 560 034. It is useful for checkout pages, delivery serviceability checks and address forms aimed at Indian customers. Store the code as text to keep formatting predictable. The honest limit is that it accepts any six digits in range, including codes that are not currently assigned to a post office.
Pattern (JavaScript)
/^[1-9][0-9]{2} ?[0-9]{3}$/Starts at the start of the line/string, then one of the characters 1-9, then a digit, exactly 2 times, then a space, optionally (zero or one time), then a digit, exactly 3 times, then the end of the line/string.
Limit: Checks the format only; it cannot tell whether the PIN code is assigned.
Examples
Matches
- ✓ 110001
- ✓ 560 034
- ✓ 400001
Does not match
- ✗ 011001
- ✗ 11000
- ✗ 1100011
Try it
0 matches (JavaScript engine)
110001
560 034
400001
011001
11000
1100011Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^[1-9][0-9]{2} ?[0-9]{3}$/g;
const text = "110001";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^[1-9][0-9]{2} ?[0-9]{3}$')
text = '110001'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^[1-9][0-9]{2} ?[0-9]{3}$/';
$text = '110001';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^[1-9][0-9]{2} ?[0-9]{3}$");
String text = "110001";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[1-9][0-9]{2} ?[0-9]{3}$`)
text := "110001"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^[1-9][0-9]{2} ?[0-9]{3}$");
var text = "110001";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^[1-9][0-9]{2} ?[0-9]{3}$").unwrap();
let text = "110001";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^[1-9][0-9]{2} ?[0-9]{3}$/
text = '110001'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why can a PIN code not start with 0?
- The first digit represents one of India's postal zones, numbered 1 to 9. A leading zero therefore indicates a typo or a code from another country.
- Can I tell the state from a PIN code?
- The first two or three digits narrow it to a region or sorting district, but an exact state or city mapping requires a lookup table from India Post data.
- How do I find PIN codes inside an address string?
- Replace the ^ and $ anchors with \b word boundaries so the pattern can match within a full address line. Keep in mind that other six-digit numbers will also match.