Last active
June 17, 2017 14:37
-
-
Save blogui91/d519d11960e61d42bfd1d4be526ac5cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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