<label>Número de CUIT</label>
<input
  id="cuit"
  name="cuit"
/>
label{
  display: block;
}
input {
  display: inline-block;
  font-size: 18px;
  padding: 10px 10px !important;
  margin-top: 15px !important;
  margin-bottom: 15px !important;
  border: 1px solid #cdcdcd !important;
  outline: none;
}
const cuit = document.getElementById("cuit");

cuit.oninput = (e) => {
  e.target.value = patternMatch({
      input: e.target.value,
      template: "xx-xxxxxxxx-x",
   });
};

function patternMatch({
  input,
  template
}) {
  try {
    

    let j = 0;
    let plaintext = "";
    let countj = 0;
    while (j < template.length) {
      // code block to be
      
      if (countj > input.length - 1) {
        template = template.substring(0, j);
        break;
      }

      if (template[j] == input[j]) {
        j++;
        countj++;
        continue;
      }

      if (template[j] == "x") {
        template = template.substring(0, j) + input[countj] + template.substring(j + 1);
        plaintext = plaintext + input[countj];
        countj++;
      }
      j++;
    }

    return template
 
  } catch {
    return ""
  }
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.