validateDate()
const validateDate: (value, fieldName, minAge?, maxAge?) => string;
Validates a date field with age restrictions
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | The date to validate in MM/DD/YY format |
fieldName | string | The name of the field for error messages |
minAge? | number | The minimum allowed age (default: 13) |
maxAge? | number | The maximum allowed age (default: 120) |
Returns
string
Empty string if valid, first error message encountered if invalid
Note
Checks: required, valid MM/DD/YY format, age within range
Example
validateDate("", "Date of birth") // Returns: "Date of birth is required"
validateDate("13/01/23", "Date of birth") // Returns: "Please enter a valid date in MM/DD/YY format"
validateDate("01/01/15", "Date of birth", 18, 100) // Returns: "You must be at least 18 years old"