poppinss / indicative

Indicative is a simple yet powerful data validator for Node.js and browsers. It makes it so simple to write async validations on nested set of data.
https://indicative.adonisjs.com/
MIT License
417 stars 52 forks source link

date_format with ISO 8601? #142

Closed eliasisrael closed 7 years ago

eliasisrael commented 7 years ago

For the life of me, I can't get this to work. Is there some trick?

const myRules = {
 "dateCreated": "required|date_format:YYYY-MM-ddTHH:mm:ss.SSSZ"
}

won't accept:

{ "dateCreated": '2017-09-06T05:06:14.805Z' }

Someone, please explain my dain bramage to me.

eliasisrael commented 7 years ago

this version of the syntax from 3.0.0 doesn't appear to work either:

var indicative = require('indicative');

myRules = {
    "dateCreated":      [
        indicative.rule('date_format','YYYY-MM-ddTHH:mm:ss.SSSZ')
    ]
)
thetutlage commented 7 years ago

Will look into it now

eliasisrael commented 7 years ago

Apparently, I didn't have the moment() syntax correct. This works:

myRules = { "dateCreated": [ indicative.rule('date_format','YYYY-MM-DDTHH:mm:ss.SSSZ') ] )

(note the 'DD') As a convenience, having a couple of common date formats built into the validator might be a nice-to-have.

Something like:

var myRules = { "dateCreated": "required|date_ISO8601" }

Andreyco commented 7 years ago

@eliasisrael you can create own validation rule exactly for this ;)

thetutlage commented 7 years ago

Yes, creating a custom rule makes more sense