REGEXVAULTv2.0
Identity & PII/Passport Numbers
Verified Safe

UK Passport Number Regex for Java

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

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching uk passport number, ported and verified for Java. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. 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
// UK Passport Number
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers

import java.util.regex.Pattern;

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

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

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

Test Cases

Matches (Valid)
Rejects (Invalid)
12345678912345678
0000000011234567890
99999999912345678A
12-345-678

When to use this pattern

This pattern is drawn from the Identity & PII > Passport Numbers category and carries a ReDoS-safe certification. 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

The simple 9-digit format means any 9-digit number passes the regex check. Semantic validation (the number actually exists) requires checking against passport records, which is not publicly available.

Technical Notes

UK passport numbers are 9 digits. The format changed to a simple 9-digit number from an older alphanumeric format. HMPO (His Majesty's Passport Office) issues the numbers sequentially.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern