I am having an issue with the function "checkNumbers()"
. I am attempting to validate if my input does not exceed 10 numbers; while "isAllowedSymbol()"
is functioning correctly, the other one is not. What could be causing this problem?
function isAllowedSymbol(input)
{
var value = input.value;
var rep = /[a-zA-Z]/;
var rep2 = /[а-яА-Я]/;
if (rep.test(value))
{
value = value.replace(rep, '');
input.value = value;
if (rep2.test(value))
{
value = value.replace(rep2, '');
input.value = value;
}
}
}
var element = document.querySelector("input[name=answer]");
function checkNumbers(element) {
if (element != null && element.value.length > 10) {
element = element.replace(element, '');
}
}
<input type="text" maxlength="10" name="answer" onkeyup="isAllowedSymbol(this);checkNumbers(this);" placeholder="Enter data" > <br>