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

175
Visualizações
Is there a way to programmatically determine if an input date field is incomplete?

I'm stuck with the following question: how can I determine if an input date field is incompletely submitted? For example, if I send 12/09/aaaa as a value, the value actually sent is null, which is the same value I obtain if I send gg/mm/aaaa, i.e. the empty value. Is there a way to discriminate via JS between the two cases? (Actually, I'm using Vue.js but I think it's not so important.)

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You could regex, in this case, to validate if the provided input is a valid date format.

You could use the following regex

/^\d{2}\/\d{2}\/\d{4}$/ 

mentioned in the answer regular expression to validate datetime format (MM/DD/YYYY)

You could use (str).match(regex) in JS to use this feature.

I have shared an approach to use, regex can be updated based on use cases.

about 4 years ago · Juan Pablo Isaza Relatório

0

let date = new Date('12/09/aaaa');

date == 'Invalid Date' //This will return true in date is not valid

about 4 years ago · Juan Pablo Isaza Relatório

0

tl;dr: No, not natively

Problem

If you use the native HTML date input there is no way to differentiate between a partially filled state and a totally empty state because the native HTML date input must either be empty or have a valid date according to the spec:

4.10.5.1.7 Date state (type=date)

[...] User agents must not allow the user to set the value to a non-empty string that is not a valid date string. [...]

The value attribute, if specified and not empty, must have a value that is a valid date string.

The value sanitization algorithm is as follows: If the value of the element is not a valid date string, then set it to the empty string instead.

– reference

This means, when the input is partially filled, no matter what form or input event is triggered (submit, change, etc) the value of the input will be an empty string.

Solution

You've got to build your own custom date input.

about 4 years ago · Juan Pablo Isaza Relatório
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