Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-international-phone-number-test

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-international-phone-number-test

International mobile phone input component with mask for React Native

  • 0.0.14
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

React Native International Phone Number Input

Installation

$ 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'],
 },
};

Basic Usage

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>
  );
}

Advanced Usage Using React-Hook-Form ans Typescript

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>
  );
}

Props

  • value?: string
  • onChangeText?: (text: string) => void
  • containerStyle?: StyleProp
  • inputStyle?: StyleProp
  • withDarkTheme?: boolean
  • disabled?: boolean
  • placeholder?: string
  • placeholderTextColor?: string

Methods

  • phoneMask: (value: string, countryCode: string) => string

Contributing

  • Fork or clone this repository
  $ git clone https://github.com/AstrOOnauta/react-native-international-phone-number.git
  • Repair, Update and Enjoy 🛠️🚧⚙️

  • Create a new PR to this repository



Thanks for stopping by! 😁

Keywords

FAQs

Package last updated on 19 Dec 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc