Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Javascript Validate birth date using regex

//birth date validation
function validateBirthDate(birthDate) {
  //create regex for birth date
  const regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/;

  //return true if birth date is valid
  return regex.test(birthDate);

const result = validateBirthDate("01/01/2020");

console.log(result); //true

Enter fullscreen mode Exit fullscreen mode

Top comments (0)