Validating javascript onChange event I'm looking to simplify the below code for validating an onChange event. The allowedInput is a regex that is passed (optional) from all the form components.
    const validatedOnChange = (event: ChangeEvent&lt;HTMLInputElement&gt;): void =&gt; {
        if (isDisabled) {
            return;
        }
        if (allowedInput) {
            if (allowedInput.test(event.target.value)) {
                onChange({ name, value: event.target.value });
            }
            return;
        }
        onChange({ name, value: event.target.value });
    };

This is a common utility method used for all my React form components. Hence looking to write a readable and consistent code.
Obviously the code does have some redundancy, which violates the Don't Repeat Yourself principle.
This could be simplified by calling onChange() if allowedInput is falsey or if that is not the case then only when the call to the test method on it returns a truethy value:
const validatedOnChange = (event: ChangeEvent&lt;HTMLInputElement&gt;): void =&gt; {
    if (isDisabled) {
        return;
    }
    if (!allowedInput || allowedInput.test(event.target.value)) {
        onChange({ name, value: event.target.value });
    }
};

One could opt to take the return early approach, which might be more readable and decrease the indentation on the call to onChange() but would have an extra line:
    if (allowedInput &amp;&amp; !allowedInput.test(event.target.value)) {
        return;
    }
    onChange({ name, value: event.target.value });