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

222
Visualizações
Input date validation while typing the date yyyy-mm-dd format

I am trying to block the user to enter invalid numbers. I am currently supporting the years from 1901 to 20XX. So for example when the user is trying to enter the year from either 2 or 1 should be fine in the first letter but not 3. In the second character, a user can enter 9 or 0 and they shouldn't enter 3 or 4, etc. this is my current implementation but it's blocking from the first character because it's checking for the entire string at once.

                   <TextField
                    fullWidth
                    sx={{ pr: 3 }}
                    value={dateOfBirth}
                    {...params}
                    onInput={(e) => {
                      const regex =
                        /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
                      console.log(e.target.value);
                      e.target.value = regex.test(e.target.value)
                        ? e.target.value
                        : "";
                    }}
                 
                  />
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