Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

634
Visualizações
How to validate a date using Yup in case of wrong two digit year input

I'm trying to validate a date. The input field, which is a date picker could have the input 05.01.20 which results in the date Sun Jan 05 0020 00:00:00 GMT+0053. This is obviously not a useful year value, so I would expect an error message for wrong input format (which should be YYYY instead of YY - in this example 05.01.2020).

This is my attempt, which is working but hacky, as it returns a boolean value in the transform function. I guess this is not the correct validation method. Also I would like to add a minimum date value (after checking if format is valid). If date is older then Jan 1, 2000, it should throw an error.

Yup.object().shape({
    birthday: Yup.date()
    .transform((value, originalValue) => {
        const year = originalValue.getFullYear() || 0
        return year > 2000 ? originalValue : false
    })
    .typeError('Wrong format (DD.MM.YYYY)')
    .nullable()
    .required('Birthday missing')
})
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda