Skip to content

Instantly share code, notes, and snippets.

@Akifcan
Last active March 31, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akifcan/de1a19d277acf08b018e68e012cac5a3 to your computer and use it in GitHub Desktop.
Save Akifcan/de1a19d277acf08b018e68e012cac5a3 to your computer and use it in GitHub Desktop.
correctjs example
import { correct } from 'correctjs'
or
const correct = require('correctjs')
const name = ''
const email = 'test@hotmail'
const age = '109a'
const customReg = '44'
const point = 20
const sayHi = 'hello'
const lentest = 'tttttt'
let check = correct(
[
{
value: name,
fieldName: 'name',
validations: [
{
'type': 'required',
},
{
'type': 'min|5',
'message': 'name must be at least 5 character',
},
{
'type': 'max|15',
'message': 'name not be greater than 15 character'
},
]
},
{
value: email,
fieldName: 'email',
validations: [
{
'type': 'required',
'message': 'email required'
},
{
'type': 'max|20',
'message': 'email must be at least 5 character'
},
{
'type': 'email',
'message': 'email address format wrong'
}
]
},
{
value: age,
fieldName: 'age',
validations: [
{
'type': 'required',
'message': 'age is required'
},
{
'type': 'number',
'message': 'age must be number'
},
]
},
{
value: customReg,
fieldName: 'custom regex',
validations: [
{
'type': 'required',
'message': 'please enter phone number'
},
{
'type': 'customRegex|^\\d+$',
'message': 'custom regex'
},
]
},
{
value: point,
fieldName: 'point',
validations: [
{
'type': 'between|10-30',
'message': 'point must be between 10 and 20'
},
]
},
{
value: sayHi,
fieldName: 'sayhi',
validations: [
{
'type': 'required',
'message': 'sayhi required'
},
{
'type': 'startsWith|h',
'message': 'must start with h'
},
]
},
{
value: sayHi,
fieldName: 'sayHi',
validations: [
{
'type': 'required',
'message': 'sayhi required'
},
{
'type': 'endsWith|o',
'message': 'must end with o'
},
]
},
{
value: lentest,
fieldName: 'len test',
validations: [
{
'type': 'matchLength|6',
'message': 'lentest must be 6 character'
},
]
},
]
)
if(check == true){
console.log('OK!')
}else{
console.log(check)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment