Skip to content

Commit

Permalink
Merge pull request #56 from paolofajardo/verificaciones-carrito
Browse files Browse the repository at this point in the history
Verificaciones para campos de ingreso de datos
  • Loading branch information
paolofajardo authored Oct 28, 2023
2 parents d688644 + 8ab03ee commit 5919a59
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions cart.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ <h4 class="modal-title">Forma de Pago</h4>
<label for="expirationDate">Vencimiento (MM/AA):</label>
<input type="text" id="expirationDate" class="form-control py-2 payment-field" pattern="\d{2}/\d{2}" required>
</div>

</div>
</div>
</div>
Expand Down
28 changes: 28 additions & 0 deletions js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,34 @@ function disablePaymentFields(fieldGroup) {
});
}

// Obtén el elemento de entrada
const expirationDateInput = document.getElementById("expirationDate");

// Agrega un event listener para el evento "input"
expirationDateInput.addEventListener("input", function() {
// Elimina cualquier carácter que no sea un dígito
this.value = this.value.replace(/\D/g, "");

// Asegúrate de que no haya más de 4 caracteres
if (this.value.length > 4) {
this.value = this.value.slice(0, 4);
}

// Agrega la barra "/" después de los primeros 2 caracteres del mes
if (this.value.length >= 2) {
this.value = this.value.slice(0, 2) + "/" + this.value.slice(2);
}
});

// Agrega un event listener para el evento "change"
expirationDateInput.addEventListener("change", function() {
// Verifica si el campo tiene exactamente 4 caracteres
if (this.value.length !== 5) {
alert("El campo debe tener 4 caracteres (MM/AA).");
this.value = "";
}
});


setInterval(precioFinal, 100);
setInterval(calcularEnvio, 100);
Expand Down

0 comments on commit 5919a59

Please sign in to comment.