title: Moment.js: Check if string is in correct format
body: <p>I was checking if the moment string is correct using a regex with a specific format string:</p>
  
  <pre><code>const isCorrect = isCorrectFormat('12/06/2016 20:20:20:444')
  </code></pre>
  
  <p>and the <strong>isCorrectFormat</strong> function:</p>
  
  <pre><code>const isCorrectFormat = (dateString) =&gt; {
      const regex = /[0-3][0-9][/][0-9]{2}[/][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]*/
      return regex.test(dateString)
  }
  </code></pre>
  
  <p>And of course the result in this case will be <strong>false</strong> because is not using the same format.</p>
  
  <p>The problem that I want to solve now, is send the format also as parameter, but instead of using a regex, I want to use directly the <a href="https://momentjs.com" rel="nofollow noreferrer">moment</a> format speficifation.</p>
  
  <pre><code>const isCorrect = isCorrectFormat(
      '12/06/2016 20:20:20:444',
      'MM/DD/YYYY HH:mm:ss.SSS'
  )
  </code></pre>
  
  <p>But I don't have idea how to implement it... I found in the documentation of moment and I don't see any method to test it. Any idea?</p>
  
  <p>Thank you so much!!</p>