百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-phone-input

> 前端框架
开源

适用于 React Native 的电话输入框

395 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

适用于 React Native 的电话输入框

React Native Phone Input

Phone input box for React Native

Installation

bash
npm i react-native-phone-input --save

Basic Usage

javascript
import PhoneInput from 'react-native-phone-input'

render(){
    return(
        
    )
}

see full basic example

Custom Your Own Picker

  1. in componentDidMount, keep this.phone.getPickerData() in state
  2. create function for open your modal (onPressFlag in example)
  3. \
  4. call this.phone.selectCountry for set country of \
javascript
componentDidMount(){
    this.setState({
        pickerData: this.phone.getPickerData()
    })
}

onPressFlag(){
    this.myCountryPicker.open()
}

selectCountry(country){
    this.phone.selectCountry(country.iso2)
}

render(){
    return(
        
             { this.phone = ref; }}
                onPressFlag={this.onPressFlag}
            />

             { this.myCountryPicker = ref; }}
                data={this.state.pickerData}
                onChange={(country)=>{ this.selectCountry(country) }}
                cancelText='Cancel'
            />
        
    )
}

see full custom picker example

Custom Library Picker

use awesome react-native-country-picker-modal to select country

javascript
onPressFlag(){
    this.countryPicker.openModal()
}

selectCountry(country){
    this.phone.selectCountry(country.cca2.toLowerCase())
    this.setState({cca2: country.cca2})
}

render(){
    return(
        
             { this.phone = ref; }}
                onPressFlag={this.onPressFlag}
            />

             { this.countryPicker = ref; }}
                onChange={(value)=> this.selectCountry(value)}
                translation='eng'
                cca2={this.state.cca2}
            >
                
            
        
    )
}

see full custom library picker example

Custom Countries

javascript

Configuration

Properties:

Property Name Type Default Description
initialCountry string 'us' initial selected country
allowZeroAfterCountryCode bool true allow user input 0 after country code
disabled bool false if true, disable all interaction of this component
value string null initial phone number
style object null custom styles to be applied if supplied
flagStyle object null custom styles for flag image eg. {{width: 50, height: 30, borderWidth:0}}
textStyle object null custom styles for phone number text input eg. {{fontSize: 14}}
textProps object null properties for phone number text input eg. {{placeholder: 'Telephone number'}}
textComponent function TextField the input component to use
offset int 10 distance between flag and phone number
pickerButtonColor string '#007AFF' set button color of country picker
pickerBackgroundColor string 'white' set background color of country picker
pickerItemStyle object null custom styles for text in country picker eg. {{fontSize: 14}}
cancelText string 'Cancel' cancel word
confirmText string 'Confirm' confirm word
buttonTextStyle object null custom styles for country picker button
onChangePhoneNumber function(number) null function to be invoked when phone number is changed
onSelectCountry function(iso2) null function to be invoked when country picker is selected
onPressFlag function() null function to be invoked when press on flag image
countriesList array null custom countries list
autoFormat bool false automatically format phone number as it is entered

Functions:

Function Name Return Type Parameters Description
isValidNumber boolean none return true if current phone number is valid
getNumberType string none return true type of current phone number
getValue string none return current phone number
getFlag object iso2:string return flag image
getAllCountries object none return country object in country picker
getPickerData object nont return country object with flag image
focus void none focus the phone input
blur void none blur the phone input
selectCountry void iso2:string set phone input to specific country
getCountryCode string none return country dial code of current phone number
getISOCode string none return country iso code of current phone number
onPressCancel func none handler to be called when taps the cancel button
onPressConfirm func none handler to be called when taps the confirm button

Issues· 91 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcountry-pickerinputphonereact-native

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架