Write validateSignup(form, today). form is a raw object from a request body; today is the current date as YYYY-MM-DD (always valid).
General rule: a field whose value is null or undefined (or that is not in form) is missing. A present value that is not a string gets code "format". Each field reports at most one error: the first failing check below.
email: trim it. Missing or blank after trimming:required. Otherwise it must match/^[^\s@]+@[^\s@]+\.[^\s@]+$/, elseformat. The result holds the trimmed, lowercased email.password: used exactly as given (no trimming). Missing or"":required. Fewer than 10 characters:too_short. No ASCII digit0-9:no_digit.confirmPassword: checked only whenpasswordis a non-empty string.mismatchunless it is exactly equal topassword.birthDate: missing or"":required. Must be exactlyYYYY-MM-DDand a real calendar date (Gregorian leap years), elseformat. The person must be at least 13 years old ontoday, elsetoo_young: they turn 13 on the same month and day 13 years after birth, except that someone born on February 29 has that birthday on March 1 in a non-leap year.referralCode: optional. Missing, or a string that is blank after trimming, means absent. Otherwise the trimmed value must match/^[A-Z]{3}-\d{4}$/, elseformat.
On success return { email, password, birthDate, referralCode } (referralCode absent when not given; the others as described). Other keys of form are ignored and form is not modified.
If any field has an error, fail with { kind: "invalid", errors }, where errors lists every failing field as { field, code } in the field order above.