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

221
Views
why date format give true value using momentjs?

I am trying to validate formate . but I am getting true value .

why ?

  var a = "11-01-2022";
  console.log("sss", moment(a, "YYYY-mm-DD").isValid());

Expected output is : false. here I am getting true why ?

var a = "2022-01-11";
      console.log("sss", moment(a, "YYYY-mm-DD").isValid());
Expected output is : true.

here is my code https://codesandbox.io/s/patient-cookies-npsit?file=/src/App.js:85-165

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to enable strict parsing. It's the third argument in the moment function.

console.log("sss", moment(a, "YYYY-mm-DD", true).isValid()); //Outputs false

Strict parsing requires that the format and input match exactly, including delimiters. Strict parsing is frequently the best parsing option.

Updated sandbox

about 4 years ago · Juan Pablo Isaza Report

0

Kindly pass third parameter for parsing.

console.log("sss", moment(a, "YYYY-mm-DD", true).isValid());
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!