ldc-web/resources/ts/otpfields.ts
2022-09-26 12:27:09 +02:00

19 lines
510 B
TypeScript

window.addEventListener("DOMContentLoaded", () => {
const elements = document.getElementsByClassName(
"otp-field"
) as HTMLCollectionOf<HTMLInputElement>;
for (const element of elements) {
element.addEventListener("input", checkFields);
}
});
function checkFields(e: Event) {
const target = e.target as HTMLInputElement | null;
if (target) {
target.value = target.value
.replace(/[^0-9.]/g, "")
.replace(/(\..*?)\..*/g, "$1");
}
}