// pretend validators use regex.test(string) import isInvalidEmail from '../pretendRegexValidators/isInvalidEmail'; import isInvalidName from '../pretendRegexValidators/isInvalidName'; import isInvalidPhoneNumber from '../pretendRegexValidators/isInvalidPhoneNumber'; export default function contactFormValidator(values) { const errors = {}; const { firstName, lastName, email, phone, } = values; // Really I'd prefer to pull all the undefined checks into a function. Or use validate-this :) if (firstName === undefined) { errors.firstName = `First Name is Required.`; } else if (isInvalidName(firstName)) { errors.firstName = `First Name cannot contain the characters we said it can't`; } if (lastName === undefined) { errors.lastName = `Last Name is Required.`; } else if (isInvalidName(lastName)) { errors.lastName = `Last Name cannot contain the characters we said it can't`; } if (email === undefined) { errors.email = `Email is Required.`; } else if (isInvalidEmail(email)) { errors.email = 'Must be a valid email.'; } if (phone === undefined) { errors.phone = `Phone is Required.`; } else if (isInvalidPhoneNumber(phone)) { errors.phone = 'Must be a valid phone number.'; } return errors; }