Height (Metric and Imperial) Regex for JavaScript
/^(?:(1[0-9]{2}|2[0-5][0-9])\s?cm)|(?:([1-8])'(?:\s?(?:0|[1-9]|1[01])"?)??)$/iWhat this pattern does
This page provides a comprehensive, battle-tested regular expression for matching height (metric and imperial), ported and verified for JavaScript. 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 JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// Height (Metric and Imperial)
// ReDoS-safe | RegexVault — Identity & PII > Biometric & Physical
const heightMetricAndImperialRegex = /^(?:(1[0-9]{2}|2[0-5][0-9])\s?cm)|(?:([1-8])'(?:\s?(?:0|[1-9]|1[01])"?)??)$/i;
function validateHeightMetricAndImperial(input: string): boolean {
return heightMetricAndImperialRegex.test(input);
}
// Example
console.log(validateHeightMetricAndImperial("175cm")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
175cm | 99cm |
175 cm | 260cm |
6'2" | 9' |
5'10" | 5'13" |
5' | 5ft 10in |
200cm | cm175 |
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 JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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