RocksonZeta / koa-validate

validate koa request params and format request params
https://github.com/RocksonZeta/koa-validate
MIT License
284 stars 32 forks source link

feature request: validate an array of object #10

Open eisneim opened 9 years ago

eisneim commented 9 years ago

it would be nice if it possible to validate array of object, for example somebody post something like this:

[
    {
        name:'aa',
        age: 23,
               tags:['ss','2333']
    },
    {
        name:'bb',
        age: 25
    },
]

we can use those code to check each object in an array of even nested array

app.use(function*(){
    // the "$" indicate this field is in an array;
    this.checkBody('$.name').len(2,10);
    this.checkBody('$.age').len(2,10);
    this.checkBody('$.tags.$').len(1,10);

})
kkschick commented 8 years ago

+1

NotJustClarkKent commented 8 years ago

+1

In our case we are passing in an array of domains and we want to validate each are a FQDN.

{
  domains: ["www.foo.com", "foo.com", "mail.foo.com"]
}

so we'd like to do something like:

this.checkBody('/domains[*]', true).isFQDN();