-2

Regex for Date Validation in mm/dd/yyyy and should be less than current date

Raquib
  • 11
  • 2
  • Does this answer your question? [How to validate date with format "mm/dd/yyyy" in JavaScript?](https://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript) – SuperStormer Nov 11 '21 at 05:45
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 12 '21 at 07:31

1 Answers1

0

You can not useRegex should be less than the current date

function formatAndLessThanCurrentDate(varDate)
{

  let today = new Date();
  today.setHours(0,0,0,0);
  let dateReg = /[0-9]{2}[\/]{1}[0-9]{2}[\/]{1}[0-9]{4}$/
  let matches =dateReg.test(varDate);
  if(matches){
    if(new Date(varDate) < today) {
      alert("Working!");
    }
    else
    {
       alert("not less than CurrentDate!");
    }
  }
  else{
    alert("not matches!");

  }
 }

formatAndLessThanCurrentDate("10/12/2021");
Mohammad Ali Rony
  • 4,695
  • 3
  • 19
  • 33