REGEXVAULTv2.0
Identity & PII/Biometric & Physical
Verified Safe

Height (Metric and Imperial) Regex for Java

/^(?:(1[0-9]{2}|2[0-5][0-9])\s?cm)|(?:([1-8])'(?:\s?(?:0|[1-9]|1[01])"?)??)$/i

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching height (metric and imperial), 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
// Height (Metric and Imperial)
// ReDoS-safe | RegexVault — Identity & PII > Biometric & Physical

import java.util.regex.Pattern;

public class HeightMetricAndImperialValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^(?:(1[0-9]{2}|2[0-5][0-9])\\s?cm)|(?:([1-8])\'(?:\\s?(?:0|[1-9]|1[01])\"?)??)$");

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

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

Test Cases

Matches (Valid)
Rejects (Invalid)
175cm99cm
175 cm260cm
6'2"9'
5'10"5'13"
5'5ft 10in
200cmcm175
183 CM

When to use this pattern

This pattern is drawn from the Identity & PII > Biometric & Physical 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

Height alone is rarely identifying. Combined with name, DOB, and other attributes, it becomes part of a biometric profile. The GDPR biometric data category applies when height is processed to uniquely identify a person.

Technical Notes

Metric range: 100-259 cm (practical human height range). Imperial: 1-8 feet, 0-11 inches. Height is body measurement data — classified as sensitive personal data in some jurisdictions (biometric data under GDPR if combined with other identifiers).

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