Skip to content

Fails to enforce required format when value is a number string #25

@ljle

Description

@ljle

Context

  • node version: v12.10.0
  • joi version: v16.1.4
  • environment (node, browser): node

What are you trying to achieve or the steps to reproduce ?
I'm trying to validate that a date string follows a format, but it throws no error when I use it with Joi.assert for numbers that are strings.

const Joi = require('@hapi/joi')
    .extend(require('@hapi/joi-date'));

const schema = Joi.date().format('YYYY-MM-DD');
Joi.assert('1', schema)
Joi.assert('10', schema)
Joi.assert('1000', schema)

https://runkit.com/ljle/joi-joi-date-potential-bug-with-number-strings

If I run it with something like 100x or 1-1, it does throw the error.

Which result you had ?

undefined

What did you expect ?
A ValidationError thrown

exports.ValidationError: "value" must be in YYYY-MM-DD format

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions