I have a task that consists in masking the value that the user puts in an input.
So far I have got to validate the number but can not mask it.
What I need is that a number, for example
13589294579294 changes to ########9294.
I have done the functions and they work as you can see I am importing those functions.
The thing is that every time I use the function validator.maskify()
the console says:
Uncaught TypeError: can't assign to property "innerHTML" on "324543": not an object
My Code:
Javascript:
let numero = document.getElementById('numeroTarjeta').value
numero.innerHTML = validator.maskify(numero)
if (validator.isValid(numero) === true) {
let tarjeta_valida = document.createElement('div')
tarjeta_valida.setAttribute('div', 'tarjetaValida')
let div_tarjeta = document.querySelector('.tarjeta')
div_tarjeta.appendChild(tarjeta_valida)
} else {
let tarjeta_invalida = document.createElement('div')
tarjeta_invalida.setAttribute('div', 'tarjetaInvalida')
let div_tarjeta = document.querySelector('.tarjeta')
div_tarjeta.appendChild(tarjeta_invalida)
}
console.log(numero)
console.log(validator);
HTML:
<section>
<div class="tarjeta">
<h4 class="tu-tarjeta">TU TARJETA DE CRÉDITO</h4>
<span class="compras">COMPRAS</span>
<br>
<label for="nuemeroTarjeta">número de tarjeta:</label> <br>
<input id="numeroTarjeta" type="text" placeholder="Introduce tu numero de tarjeta">
<button>validar</button>
<br>
<span>VENCIMIENTO MM/YY</span>
</div>
</section>
