Gopesh Gopesh - 1 month ago 5
Javascript Question

Regular expression for date format- dd-mm-yyyy in Javascript

I need a regular expression for date format: dd-mm-yyyy in Javascript.

Answer

function parseDate(str) {
  var m = str.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/);
  return (m) ? new Date(m[3], m[2]-1, m[1]) : null;
}


Comments