Skip to content

Instantly share code, notes, and snippets.

@blogui91
Last active June 17, 2017 14:37
Show Gist options
  • Save blogui91/d519d11960e61d42bfd1d4be526ac5cd to your computer and use it in GitHub Desktop.
Save blogui91/d519d11960e61d42bfd1d4be526ac5cd to your computer and use it in GitHub Desktop.
import Validator from 'laravalidator-js'
let data = {
email: "Cesar.23@@santana.com", //Wrong
fullname: "Cesar A",
age: "16",
};
let rules = {
fullname: ['required'],
email: ['email'],
age : ['numeric','customvalidator']
};
let messages = {
fullname: {
required: "fullname is required"
},
age: {
numeric: "This field must be numeric",
customvalidator: "Custom message"
}
};
let custom_validators = {
customvalidator(value) {
//enter your validation here
return true
},
anothervalidator(value) {
}
}
let validator = Validator.make(data, rules, messages, custom_validators);
if (validator.passes()) {
console.log("Valid for create/update")
}
if (validator.fails()) {
console.log(validator.messages)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment