Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
Created October 25, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolframkriesing/1ed059f3351188bfe211ba22c96990bd to your computer and use it in GitHub Desktop.
Save wolframkriesing/1ed059f3351188bfe211ba22c96990bd to your computer and use it in GitHub Desktop.
const validateBranching = ({ name, type, email, phone }) => {
if (!isValidName(name))
return Required('name');
if (type === 'email') {
if (!isValidEmail(email))
return InvalidEmail(email);
if (phone && !isValidPhone(phone))
return Optional(InvalidPhone(phone));
return { type, name, email, phone };
}
if (type === 'phone') {
if (!isValidPhone(phone))
return InvalidPhone(phone);
if (email && !isValidEmail(email))
return Optional(InvalidEmail(email));
return { type, name, email, phone };
}
return InvalidType(type);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment