Identity
India PAN Number Regex
The Indian Permanent Account Number is a ten-character code made of five letters, four digits and one final letter. The fourth character marks the holder type, such as P for an individual, C for a company or T for a trust, and this pattern only allows the published holder-type letters in that slot. It is useful for invoicing, tax filing, payroll and lending forms that collect PAN details. The honest limit is the final letter, which is a check character computed by the issuer and cannot be confirmed with a regular expression.
Pattern (JavaScript)
/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/Starts at the start of the line/string, then an uppercase letter, exactly 3 times, then one of the characters ABCFGHLJPT, then an uppercase letter, then a digit, exactly 4 times, then an uppercase letter, then the end of the line/string.
Limit: Checks the shape only; it cannot tell whether a document is real or valid.
Examples
Matches
- ✓ ABCPE1234F
- ✓ AAACT1234Z
- ✓ XYZHA9876K
Does not match
- ✗ ABCDE1234F
- ✗ abcpe1234f
- ✗ ABCPE123F
Try it
0 matches (JavaScript engine)
ABCPE1234F
AAACT1234Z
XYZHA9876K
ABCDE1234F
abcpe1234f
ABCPE123FCode in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/g;
const text = "ABCPE1234F";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$')
text = 'ABCPE1234F'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/';
$text = 'ABCPE1234F';
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("^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$");
String text = "ABCPE1234F";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$`)
text := "ABCPE1234F"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$");
var text = "ABCPE1234F";
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"^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$").unwrap();
let text = "ABCPE1234F";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/
text = 'ABCPE1234F'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- What does the fourth letter of a PAN mean?
- It identifies the type of holder, for example P for individual, C for company, H for Hindu undivided family, F for firm and T for trust. The pattern accepts only those published type letters in that position.
- Why is lowercase input rejected?
- PANs are issued and printed in uppercase. Convert the input to uppercase before testing so that users who type in lowercase are not blocked unnecessarily.
- Does the fifth letter follow any rule?
- For individuals it is normally the first letter of the surname, and for other entities the first letter of the name. A regex cannot know the holder's name, so the pattern accepts any uppercase letter there.
Related patterns
- India Aadhaar Number Shape^[2-9][0-9]{3} ?[0-9]{4} ?[0-9]{4}$
- US Social Security Number (SSN)^(?!000|666|9[0-9]{2})[0-9]{3}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$
- Canada SIN Shape^[1-79][0-9]{2}[ -]?[0-9]{3}[ -]?[0-9]{3}$
- EU VAT Number^(?:AT|BE|BG|CY|CZ|DE|DK|EE|EL|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK)[0-9A-Z]{8,12}$