Skip to content

Instantly share code, notes, and snippets.

@rakibulalam
Created August 29, 2017 00:41
Show Gist options
  • Save rakibulalam/983ad451cbdba3a897f5adf7ba216e11 to your computer and use it in GitHub Desktop.
Save rakibulalam/983ad451cbdba3a897f5adf7ba216e11 to your computer and use it in GitHub Desktop.
Schema validation ES6
// object validation rules
const schema = {
first: {
required:true
},
last: {
required:true
}
}
// universal validation function
const validate = (schema, values) => {
for(field in schema) {
if(schema[field].required) {
if(!values[field]) {
return false;
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment