document.addEventListener("DOMContentLoaded", () => {
const phoneInput = document.getElementById("phone");
const inputs = document.querySelectorAll(".input-group input");
// Formatage automatique du téléphone (ex: 06 12 34 56 78)
phoneInput.addEventListener("input", (e) => {
let value = e.target.value.replace(/\D/g, ""); // Conserve uniquement les chiffres
if (value.length > 10) value = value.slice(0, 10);
const formatted = value.match(/.{1,2}/g)?.join(" ") || "";
e.target.value = formatted;
});
// Validation visuelle lors de la perte de focus (Blur)
inputs.forEach((input) => {
input.addEventListener("blur", () => {
if (!input.checkValidity() && input.value.trim() !== "") {
input.classList.add("error");
} else {
input.classList.remove("error");
}
});
});
});