Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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 answers
Answer question

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 Report

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 Report

0

dateofbirth is not defined. Try to add an input.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!