I need to make a function in JavaScript that when clicking the button make sure that a specific character was entered, in this case the '
(single quotation marks). If yes, replace the single quotation mark with a blank space.
See the code below:
const charValidation = ()=> {
let inputToValidate = document.querySelectorAll(".area-input input");
for(i=0;i<inputToValidate.length;i++) {
let inputZin = inputToValidate[i].value;
if(inputZin.match(["\'"])) {
let inputEr = inputZin.replace(/\'/g, "");
inputZin.innerHTML = inputEr;
}
}
}
<span class="area-input">
<input type="text" placeholder="nome" title="não permitido caracteres especiais">
</span>
<span class="area-input">
<input type="text" placeholder="telefone" title="apenas números">
</span>
<span class="area-input">
<input type="text" placeholder="endereço" title="não permitido caracteres especiais">
</span>
<input type="button" onclick="charValidation()" value="OK">
I was thinking of getting rid of match
and simply replacing it straight.