AstrOOnauta/react-native-international-phone-number
关于
⚛️ React Native phone number input component 📱
网站与应用开发可以做什么
- 🌎 Phone Input Mask – Auto-formatting per selected country
- ✅ Validation – Optional onValidationChange callback
- 📞 Line Type Detection – Tell MOBILE, FIXED_LINE, TOLL_FREE, VOIP and more apart
- 📋 Smart Paste – Paste an E.164 number and the country switches automatically
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
React Native International Phone Number Input
📚 Full documentation: astroonauta.github.io/react-native-international-phone-number
International mobile phone input for React Native, Expo and React Native Web. Country dial code selector, flag picker, auto phone mask, validation, line-type detection, smart paste, and i18n for 33 languages.
⚠️ Install
rn-international-phone-number. This library was previously published asreact-native-international-phone-number. The npm account behind that package is no longer under the author's control, so it is frozen atv0.12.3, receives no fixes or security patches from this project, and cannot be deprecated by the author. Every release fromv0.13.0on lives here. See the migration guide.
Features
- 🌎 Phone Input Mask – Auto-formatting per selected country
- ✅ Validation – Optional
onValidationChangecallback - 📞 Line Type Detection – Tell
MOBILE,FIXED_LINE,TOLL_FREE,VOIPand more apart - 📋 Smart Paste – Paste an E.164 number and the country switches automatically
- 💡 Dynamic Placeholder – Country-aware example number as placeholder (
placeholderType="number") - 🪝 Headless Hook –
usePhoneInputexposes all state + setters for fully custom UIs - 📱 Cross-Platform – iOS, Android and Web
- 🧩 Integration – React Native CLI & Expo, functional & class components
- 🈶 i18n – 33 languages (ISO 639-1 / ISO 639-2)
- ♿ Accessibility – Screen reader friendly
Try it out
Installation
npm install rn-international-phone-number react-native-safe-area-context
npx pod-install ios
For Web (React Native CLI / Expo font setup) and full configuration, see the Installation guide.
Quick start
import React, {useState} from 'react';
import {View} from 'react-native';
import PhoneInput, {ICountry} from 'rn-international-phone-number';
export default function App() {
const [phone, setPhone] = useState('');
const [country, setCountry] = useState<ICountry | null>(null);
return (
<View style={{flex: 1, padding: 24}}>
<PhoneInput
value={phone}
onChangePhoneNumber={setPhone}
country={country}
onChangeCountry={setCountry}
/>
</View>
);
}
Common configurations
Every prop with a copy-paste snippet lives in Props by Example. The ones people reach for first:
// Dark mode
<PhoneInput theme="dark" />
// Right-to-left layout
<PhoneInput rtl language="ar" />
// Starting country / starting number (E.164 — country is inferred)
<PhoneInput defaultCountry="US" />
<PhoneInput defaultPhoneNumber="+12505550199" />
// Change the language of country names and modal copy (33 languages)
<PhoneInput language="pt" />
// Force one mask for every country
<PhoneInput customMask="(###) ###-####" />
// Restrict, exclude or pin countries (also applies to pasted/E.164 numbers)
<PhoneInput visibleCountries={['BR', 'PT', 'US']} />
<PhoneInput hiddenCountries={['RU']} />
<PhoneInput popularCountries={['BR', 'US']} />
// Lock the country, or the whole input
<PhoneInput defaultCountry="BR" modalDisabled />
<PhoneInput disabled />
// Validation and line type (MOBILE, FIXED_LINE, TOLL_FREE, VOIP…)
<PhoneInput
onValidationChange={(isValid, type, country) => setCanSubmit(isValid)}
onPhoneNumberTypeChange={(type) => setLineType(type)}
/>
// Bottom sheet sizing (mobile) — 'popup' is the default on Web
<PhoneInput modalType="bottomSheet" initialBottomsheetHeight="60%" showModalAlphabetFilter />
// Replace the caret and the flag
<PhoneInput
customCaret={() => <Icon name="chevron-down" size={20} />}
customFlag={(country) => <Image source={flags[country.cca2]} />}
/>
// Custom styles — full key list in the theming guide
<PhoneInput
phoneInputStyles={{container: {borderRadius: 12}, input: {color: '#fff'}}}
modalStyles={{content: {backgroundColor: '#111827'}, countryName: {color: '#fff'}}}
/>
// Any TextInput prop works too (except `value` / `onChangeText`)
<PhoneInput autoFocus onBlur={handleBlur} returnKeyType="done" testID="phone-input" />
Read the E.164 value for your backend from the ref:
const ref = useRef<IPhoneInputRef>(null);
<PhoneInput ref={ref} />;
ref.current?.internationalPhoneNumber; // '+5511912345678'
ref.current?.isValidPhoneNumber; // true
Documentation
| Topic | Link |
|---|---|
| Props by Example (all props) | astroonauta.github.io/.../guides/props-by-example |
| Installation | astroonauta.github.io/.../installation |
| Quick Start | astroonauta.github.io/.../quick-start |
| Props API | astroonauta.github.io/.../api/props |
| Ref API | astroonauta.github.io/.../api/ref |
usePhoneInput hook |
astroonauta.github.io/.../api/hooks |
| Utility functions | astroonauta.github.io/.../api/utilities |
| Theming, dark mode & RTL | astroonauta.github.io/.../guides/theming |
| Validation & line type | astroonauta.github.io/.../guides/validation |
| i18n (33 languages) | astroonauta.github.io/.../guides/i18n |
| Accessibility | astroonauta.github.io/.../guides/accessibility |
| Testing | astroonauta.github.io/.../guides/testing |
| React Hook Form / Formik / TanStack Form | astroonauta.github.io/.../examples |
| FAQ & Troubleshooting | astroonauta.github.io/.../faq |
| Migration guide | astroonauta.github.io/.../migration |
| Changelog | astroonauta.github.io/.../changelog |
Contributing
Fork the repo, fix or improve, and open a PR. See the Contributing guide.
License
探索相关项目
加载中…