You can put three numeric type fields side by side, it may not be the best solution but it is still an alternative.
By means of the attributes min
and max
you can control how many digits the field can receive: if the maximum is two, then the user can enter any value between 10 and 99.
I see this as something good from the point of view of usability, after all if the field only accepts numbers nothing better than opening the numeric keypad when the user accesses the site through the cell phone.
<div id='nextel'>
<input type='number' min='10' max='99'>
<input type='number' min='1' max='9999999'>
<input type='number' min='10' max='99999'>
</div>
Although there are three fields, getting the value is no problem at all. Just querySelectorAll('#nextel input')
concatenating value
of each.
# snippet:
function getNextelNumber(){
let nextel = '';
for(let input of document.querySelectorAll('.nextel input'))
nextel += input.value;
return nextel;
}
document.querySelector('button').addEventListener('click', () => {
alert(getNextelNumber());
});
.nextel input {
border:none;
border-bottom:1px solid #ccc;
outline:none;
width: 7ch
}
.nextel input:invalid {
box-shadow: none;
border-bottom-color: red
}
/* Removendo a aparência padrão do campo 'number'. */
input[type='number'] {
-moz-appearance: textfield;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
<div class='nextel'>
<input type='number' min='10' max='99'>
<input type='number' min='1' max='9999999'>
<input type='number' min='10' max='99999'>
</div>
<br><br>
<button>Qual é meu Nextel?</button>