I want to accept only 0 and 1 in input field and add spaces after every 4 digits. With the following I can add spaces but it accepts all digits. How can I restrict it to only 0 and 1 instead of all digits? I'm having difficulty in the pattern.
document.getElementById('num').addEventListener('input', function (e) {
e.target.value = e.target.value.replace(/[^\d]/g, '').replace(/(.{4})/g, '$1 ').trim();
});