/** * Research Data Validators * Pure functions to validate scientific identifiers and form inputs. */ // 1. Digital Object Identifier (DOI) Regex // Matches standard DOI formats (e.g., 10.1038/s41586-021-03491-6) const DOI_REGEX = /^10.\d{4,9}\/[-._;()/:A-Z0-9]+$/i; // 2. Email Regex (Standard RFC 5322) const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; export const validators = { /** Checks if a string is a valid DOI */ isDOI: (val: string): boolean => DOI_REGEX.test(val.trim()), /** Checks if a string is a valid institutional email */ isEmail: (val: string): boolean => EMAIL_REGEX.test(val), /** Ensures PICO instructions aren't just empty whitespace */ isValidInstructions: (val: string): boolean => val.trim().length >= 10, /** Validates PICO Data object from the backend */ hasCompletePico: (pico: any): boolean => { return !!( pico?.pico_population && pico?.pico_intervention && pico?.pico_outcome ); } };