Skip to content

Instantly share code, notes, and snippets.

@agoiabel
Last active September 2, 2018 09:44
Show Gist options
  • Select an option

  • Save agoiabel/486cbe3c560a743b4fc9dc5733ebb2cd to your computer and use it in GitHub Desktop.

Select an option

Save agoiabel/486cbe3c560a743b4fc9dc5733ebb2cd to your computer and use it in GitHub Desktop.
const validate = (value, rules) => {
let isValid = true;
for (let rule in rules) {
switch (rule) {
case 'minLength': isValid = isValid && minLengthValidator(value, rules[rule]); break;
default: isValid = true;
}
}
return isValid;
}
/**
* minLength Val
* @param value
* @param minLength
* @return
*/
const minLengthValidator = (value, minLength) => {
return value.length >= minLength;
}
export default validate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment