regex -digits and special symbols are only allowed in input

I have 2 input fields in my form (for phone number) and I should validateRe these inputs. Digits 0-9 and ()+- are only allowed and number of digits should be between 5 and 11 only {5,11}. I try to use method replace. Could you explain, how it works ?

formPhone.forEach(element => {
            element.addEventListener("input", (e) => {
               e.target.value = e.target.value.replace(/[^d()+-]{5,9}/g, '');

            })
        })