Back to Woocommerce

PhoneNumberInput

packages/js/components/src/phone-number-input/README.md

10.8.0-dev2.0 KB
Original Source

PhoneNumberInput

An international phone number input with a country code select and a phone textfield which supports numbers, spaces and hyphens. And returns the full number as it is, in E.164 format, and the selected country alpha2.

Includes mobile phone numbers validation.

Usage

jsx
<PhoneNumberInput
	value={ phoneNumber }
	onChange={ ( value, e164, country ) => setState( value ) }
/>

Props

NameTypeDefaultDescription
valueStringundefined(Required) Phone number with spaces and hyphens
onChangeFunctionundefined(Required) Callback function when the value changes
idStringundefinedID for the input element, to bind a <label>
classNameStringundefinedAdditional class name applied to parent <div>
selectedRenderFunctiondefaultSelectedRenderRender function for the selected country, displays the country flag and code by default.
itemRenderFunctionitemRenderRender function for each country in the dropdown, displays the country flag, name, and code by default.
arrowRenderFunctiondefaultArrowRenderRender function for the dropdown arrow, displays a chevron down icon by default.

onChange params

  • value: Phone number with spaces and hyphens. e.g. +1 234-567-8901
  • e164: Phone number in E.164 format. e.g. +12345678901
  • country: Country alpha2 code. e.g. US