I have the following regex named 'pattern' that I am testing to try to restrict an input to only numbers. Why are both pattern.test("a")
and pattern.test("1")
returning true?
const pattern = /^[a-zA-Z0-9]*$/;
if (!pattern.test(event.target.value)) {
event.target.value = event.target.value.replace(/[^a-zA-Z0-9]/g, "");
}