Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate array of object #16

Open
azwar opened this issue Jun 6, 2018 · 1 comment
Open

Validate array of object #16

azwar opened this issue Jun 6, 2018 · 1 comment

Comments

@azwar
Copy link

azwar commented Jun 6, 2018

Hi this validation library is so easy to use, thank you for your effort.
Now I am looking for example of validation for array of object, but not found.

How to use this validation to validate array of object?
For example I have data array of users, how to validate it?

Thank you.

@kolobashek
Copy link

const validateRules = {
    firstname: { minlength: 2, maxlength: 15, required: true },
    lastname: { minlength: 3, maxlength: 7, required: true },
    email: { email: true, required: true }, 
    password: { password: true, required: true },
    phone: { minlength: 10, numbers: true, required: true},
    rulesChecked: {true: true}
}

inputValidation = (fields) => {
     const array = (typeof fields === 'string') ? [fields] : fields
     array.map(field => {
        this.validate({
           [field]: validateRules[field]
        })
    })
}

and call like:
   inputValidation(['input1', input2])
or
   inputValidation('input1')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants