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

236
Visualizações
validation of date of birth in javascript

I want the validation for date of birth. I have used new Date method so that i should not get date after today. But even though i insert date after today it doesn't show invalid date.

var pattern = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/
var date= new Date();
if (dateofbirth == "" || dateofbirth == null||!pattern.test(dateofbirth)) {
    alert("invalid date of birth should in yyyy-mm-dd");
    return false;
}
else if(dateofbirth >date){
    alert("invalid date");
    return false;
}
else{
    alert("valid date");
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can you my code :

var validation = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/
     var date= new Date();
        if (dateofbirth == "" || dateofbirth == null||!validation.test(dateofbirth)) {
            alert("Date of Birth is Invalid it should in yyyy-mm-dd");
            return false;
        }
        else if(dateofbirth >date.getFullYear()){
            alert("Invaid Date");
            return false;
        }
        else{
            alert("Your Date is Valid");
        }
about 4 years ago · Juan Pablo Isaza Relatório

0

var pattern = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/
     var date= new Date();
        if (dateofbirth == "" || dateofbirth == null||!pattern.test(dateofbirth)) {
            alert("invalid date of birth should in yyyy-mm-dd");
            return false;
        }
        else if(dateofbirth >date.getFullYear()){
     // get full year give current year you can compare with that year 
    // to date of birth
            alert("invalid date");
            return false;
        }
        else{
            alert("valid date");
        }
about 4 years ago · Juan Pablo Isaza Relatório

0

dateofbirth is not defined. Try to add an 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