File size: 994 Bytes
20b2853 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /**
* 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
);
}
};
|