Skip to content

Instantly share code, notes, and snippets.

@blogui91
Created June 17, 2017 15:42
Show Gist options
  • Save blogui91/fdaefe259d24d126aa2cb7341fbc0256 to your computer and use it in GitHub Desktop.
Save blogui91/fdaefe259d24d126aa2cb7341fbc0256 to your computer and use it in GitHub Desktop.
import ClientValidator from 'validators/Client.validator'
let clientData = {
fullname : 'Cesar Santana',
email : 'example@@email.com', //Wrong
age : 'asdf' //Wrong
}
let validation = ClientValidator.make(clientData)
/*
* The make function returns an object with these properties:
* has() : Boolean //Verify if a specified item has error.
* first() : Array //Get the first field with error.
* get() : Array //Get a specified field with error.
* passes() : Boolean //Check if the validation does not have errors.
* fails() : Boolean // Check if validation has errors.
*/
if(validation.passes(){
//saveClient();
}else if(validation.fails()){
console.error(validation.messages) //Show the
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment