International phone number input for React Native with country picker supporting 235 countries. Uses ruimarinho/google-libphonenumber to validate input and automatically translates to valid e164 format.
yarn add @sesamsolutions/phone-input
or
npm install @sesamsolutions/phone-input
import PhoneInput from '@sesamsolutions/phone-input'
import React from 'react'
import { Alert, View } from 'react-native'
import PhoneInput from '@sesamsolutions/phone-input'
const App = () => {
const handleChange = (data) => {
if (data.isValid) {
Alert.alert(data.e164)
} else {
console.log(data.input + ' is not a valid phone number')
}
}
return (
<View style={{ alignItems: 'center', flex: 1, justifyContent: 'center' }}>
<PhoneInput
initialCountry="US"
onChange={handleChange} />
</View>
)
}
export default App
Set the initial country and dial code. Defaults to US
.
Returns an object containing information about the Phone number every time the input or value
changes.
countryCode
: currently selected country code.null
if not selected.dialCode
: current dial code.null
if not selected.e164
: e164 valid phone number.null
if invalid.input
: raw phone number input. Same asonChangePhoneNumber
.isValid
:boolean
indicating if input is a valid phone number.
Returns current raw input string
. Use onChange
instead to benefit from additional validations.
Changes the current input. Be careful not to update this with onChange
. This will cause an endless loop.
boolean
indicating whether custom dial code input should be allowed or not. When set to false you can only select dial codes from the country picker. Defaults to true
.
Hide the keyboard automatically when the input is considered valid e164 format. Defaults to true
.
Customize the phone number input.
Customize text inside the phone number input.