Phone Number Input

Default


NOTE: Error state is handled by default, validating length (too long or too short) relative to the selected country’s phone format and enforcing numeric-only values for all countries.

Preferred Countries


Preferred countries will display in the order they are listed with the first country preselected, and all non-preferred countries listed alphabetically below a section separator within the remaining dropdown.

Initial Country


Setting an initial country preselects that country within the input as well as the country dropdown.

Limited Countries


Limiting countries removes all countries from the dropdown except your selections.

Form Validation


Clearing the Input Field


To clear a number inside the input element, create a ref inside your parent component, pass it to the kit's ref prop, and use ref.current.clearField().

clearField() is a custom function inside the kit to clear numbers and the error message while still providing validation.

Accessing the Input Element


To access the kit's input element attributes or add event listeners, create a ref inside your parent component, pass it to the kit's ref prop, and use ref.current.inputNode() with your desired attribute or event listener inside a useEffect hook. useEffect is necessary because the ref will be initially undefined. Calling useEffect with an empty dependency array ensures your event listeners won't be added twice.

inputNode() is a custom function inside the kit that returns the input DOM element and its attributes. For example, to get the name attribute, use ref.current.inputNode().name


Available Props