document.addEventListener('DOMContentLoaded', function () {
const inputs = document.querySelectorAll('input[type="number"]');
inputs.forEach(function(input) {
// Mobile keyboard
input.setAttribute('inputmode', 'numeric');
// Prevent more than 10 digits
input.addEventListener('keydown', function(e) {
// Allow control keys
const allowedKeys = [
'Backspace',
'Delete',
'ArrowLeft',
'ArrowRight',
'Tab'
];
if (allowedKeys.includes(e.key)) {
return;
}
// Allow only numbers
if (!/^\d$/.test(e.key)) {
e.preventDefault();
return;
}
// First digit must be 6-9
if (this.value.length === 0 && !['6','7','8','9'].includes(e.key)) {
e.preventDefault();
return;
}
// Max 10 digits
if (this.value.length >= 10) {
e.preventDefault();
}
});
});
});