# Check number format

<input id="user-number" type="number" />
<output id="formatted" />
  const output = document.getElementById('formatted')
    .addEventListener('input', (e) => {
      const chars = String(e.target.value)
        .map((c, k) => (k > 0 && k % 3 === 0 ? c + ',' : c))
      output.innerText = chars

How would we check the formatted output? We could say that the formatted output should match a regular expression.

The regular expression can lead an error though. For example, the same regular expression matches incorrectly formatted number. For example, the program could incorrectly set the output to "000" and it would still work!

Since we know the number, simply check for the expected string without any regular expression logic in the spec.

cy.contains('#formatted', '1,234,567')