Skip to main content

isWithinAgeRange()

const isWithinAgeRange: (value, minAge, maxAge) => string;

Validates that a birth date results in an age within the specified range

Parameters

ParameterTypeDescription
valuestringThe birth date in MM/DD/YY format
minAgenumberThe minimum allowed age
maxAgenumberThe maximum allowed age

Returns

string

Empty string if valid, error message if invalid

Note

Years 00-49 are interpreted as 2000-2049, years 50-99 as 1950-1999

Example

isWithinAgeRange("01/01/15", 13, 120) // Returns: "You must be at least 13 years old."
isWithinAgeRange("01/01/00", 13, 120) // Returns: "" (if age is between 13-120)