Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
react-native-international-phone-number-test
Advanced tools
Readme
$ npm i --save react-native-international-phone-number
OR
$ yarn add react-native-international-phone-number
AND
Update your
metro.config.js
file:
module.exports = { ... resolver: { sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs', 'json'], }, };
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import {
phoneMask,
PhoneInput,
} from 'react-native-international-phone-number';
export default function App() {
const [selectedCountry, setSelectedCountry] = useState(undefined);
const [phoneInput, setPhoneInput] = useState('');
return (
<View style={{ width: '100%', flex: 1, padding: 24 }}>
<PhoneInput
selectedCountry={selectedCountry}
setSelectedCountry={setSelectedCountry}
value={phoneInput}
onChangeText={(newValue) =>
setPhoneInput(
phoneMask(newValue, selectedCountry.callingCode[0])
)
}
/>
<View style={{ marginTop: 10 }}>
<Text>
Country:{' '}
{`${selectedCountry?.name} (${selectedCountry?.cca2})`}
</Text>
<Text>
Phone: {`${selectedCountry?.callingCode[0]} ${phoneInput}`}
</Text>
</View>
</View>
);
}
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import {
phoneMask,
PhoneInput,
} from 'react-native-international-phone-number';
import { Country } from 'react-native-country-picker-modal';
import { Controller, FieldValues, useForm } from 'react-hook-form';
interface FormProps extends FieldValues {
phoneNumber: string;
}
export default function App() {
const [selectedCountry, setSelectedCountry] = useState<
undefined | Country
>(undefined);
const { control, handleSubmit, resetField } = useForm();
function onSubmit(form: FormProps) {
Alert.alert(
'Advanced Result',
`${selectedCountry?.callingCode[0]} ${form.phoneNumber}`
);
resetField('phoneNumber');
}
return (
<View style={{ width: '100%', flex: 1, padding: 24 }}>
<Controller
name="phoneNumber"
control={control}
render={({ field: { onChange, value } }) => (
<PhoneInput
selectedCountry={selectedCountry}
setSelectedCountry={setSelectedCountry}
value={value}
onChangeText={(newValue) =>
onChange(
phoneMask(newValue, selectedCountry.callingCode[0])
)
}
/>
)}
/>
<Button
style={{
width: '100%',
marginTop: 10,
backgroundColor: '#90d7ff',
}}
onPress={handleSubmit(onSubmit)}
/>
<Text>Submit</Text>
</Button>
</View>
);
}
value?
: stringonChangeText?
: (text: string) => voidcontainerStyle?
: StylePropinputStyle?
: StylePropwithDarkTheme?
: booleandisabled?
: booleanplaceholder?
: stringplaceholderTextColor?
: stringphoneMask
: (value: string, countryCode: string) => string $ git clone https://github.com/AstrOOnauta/react-native-international-phone-number.git
Repair, Update and Enjoy 🛠️🚧⚙️
Create a new PR to this repository
FAQs
International mobile phone input component with mask for React Native
We found that react-native-international-phone-number-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.