Client/Server side validation library based on Laravel.
$ npm install syncano-validate
import {validate} from 'syncano-validate'
const data = {
firstName: 'John',
lastName: 'Doe',
username: 'john.doe'
email: 'john.doe@example.com',
age: 43,
gender: 'male',
phoneNumber: '555-444-333',
birthDate: '08/25/2017'
}
const rules = {
firstName: 'required|min:2',
lastName: 'required|min:2',
username: 'required|unique:users,username',
email: 'required|email',
age: 'required|numeric|min:18',
gender: 'in:male,female',
phoneNumber: 'regex:[0-9]{3}?-?[0-9]{3}?-?[0-9]{3}',
birthDate: 'date'
}
validate(data, rules)
.then(() => {
// All params valid! Continue code...
})
.catch(errors => {
// Handle errors
})
- After (Date)
- Alpha Dash
- Before (Date)
- Between
- Confirmed
- Date Format
- Different
- Dimensions (Image Files)
- File
- Filled
- Image (File)
- In Array
- IP Address
- JSON
- MIME Types
- MIME Type By File Extension
- Nullable
- Not In
- Present
- Same
- Size
- String
- Timezone
- Unique (Database)