const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ /** * Validates an email address. * @param value - The email address to validate * @returns An error message if invalid, null if valid or empty */ export function validateEmail(value: string): string | null { if (!value) { return null } if (!EMAIL_REGEX.test(value)) { return "Please enter a valid email address" } return null } /** * Validates a Telegram handle. * @param value - The Telegram handle to validate (with or without @ prefix) * @returns An error message if invalid, null if valid or empty */ export function validateTelegram(value: string): string | null { if (!value) { return null } const handle = value.startsWith("@") ? value.slice(1) : value if (handle.length < 5) { return "Telegram handle must be at least 5 characters" } if (!/^[a-zA-Z0-9_]+$/.test(handle)) { return "Telegram handle can only contain letters, numbers, and underscores" } return null }