I have looked at this post to help me (regular expression in javascript which allows backspace), but still, I can not use my backspace to delete characters.
I have tried different variations with
(/[0-1,\b]/g)
(/[0-1][\b]/g)
(/[0-1]+[\b]/g)
...nothing is working.
Here is my whole function:
binary.addEventListener('keydown', (event) => {
if (event.key.match(/[0-1]/g)) {
return event;
} else {
event.preventDefault();
}
});
Event handler is attached to <textarea id="binary" placeholder="Binary..." type="text"></textarea>.
I have tried to remove preventDefault(), but my regex does not apply then.