🌐 Text Input Component for validating and formatting international phone numbers.

Overview

Demo in action

React Native Intl Phone Field

npm (scoped)

Try the Expo Snack 👏

🕹️ Demo

It's a javascript-only (no native code) component that can run in iOS, Android, Expo & React Native Web. Below you can gifs of the demo app that showcases the component in action.

iOS Example App Gif Android Example App Gif

Click on the image to see it in a larger size.

👋 Introduction

A simple <TextInput> that validates and formats international phone numbers using Google's library libphonenumber and phonenumber-js. Works with pre-propulated data and displays an emoji flag if country code is derived from the number. Additionally, adds a + sign infront of the number, so it's considered international.

⚙️ Installation

yarn add react-native-intl-phone-field

✂️ Usage

import IntlPhoneField from 'react-native-intl-phone-field';

<IntlPhoneField
  onEndEditing={(result) => console.log(result)}
  onValidation={(isValid) => console.log(isValid)}
  defaultCountry="BG"
  defaultPrefix="+359"
  defaultFlag="🇧🇬"
/>

For more detailed example, take a look at the demo app inside example/.

Props

Property Type Default Description
flagUndetermined string? Displayed when country code cannot be derived from current phone number.
onEndEditing function undefined Callback that is called when text input ends text input ends.
It receives result.
onValidation function undefined Callback that is called each time the validation status changes.
onValueUpdate function undefined Callback that is called each time the underlying value changes.
defaultCountry string undefined Two letter code for default country, eg. BG
defaultPrefix string undefined Default number prefix, eg. +359
defaultValue string undefined Default value for the TextInput, if you want to pre-populate it.
defaultFlag string undefined Emoji for the default flag, eg. 🇧🇬
containerStyle object undefined Styles for the component's wrapper <View />
flagContainerStyle object undefined Styles for the flag emoji wrapper <View />
flagTextStyle object undefined Styles for the flag emoji <Text />
textInputStyle object undefined Styles for the underlying <TextInput />
textInputProps object undefined Additional props for the underlying <TextInput />

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

You might also like...

An API for producing and validating ActivityPub objects.

ActivityHelper A library that exports an API for producing and validating ActivityPub objects. In a federated system bound together by protocols, it's

May 2, 2022

Fully-typed utilities for defining, validating and building your document head

zhead Typed utilities for defining, validating and building best-practice document head's. Status: Pre-release Please report any issues 🐛 Made poss

Dec 21, 2022

Little Javascript / Typescript library for validating format of string like email, url, password...

String-Validators Little Javascript / Typescript library for validating format of string like email, url, password... Signaler un Bug · Proposer une F

Oct 14, 2022

A Bootstrap plugin to create input spinner elements for number input

A Bootstrap plugin to create input spinner elements for number input

bootstrap-input-spinner A Bootstrap / jQuery plugin to create input spinner elements for number input. Demo page with examples Examples with floating-

Nov 7, 2022

Verify your E-Mail and Phone Number using link sent over mail and sms.

Verify your E-Mail and Phone Number using link sent over mail and sms.

Phone-and-Mail-Verification-With-Link Verify your E-Mail and Phone Number using link sent over mail and sms. Endpoints POST /user/create Body { "n

Sep 14, 2022

Verify your E-Mail and Phone Number using link sent over mail and sms.

Verify your E-Mail and Phone Number using link sent over mail and sms.

Send Verification Link ✅ Explore the docs » • Report Bug • Request Feature • About The Project Verify your E-Mail and Phone Number using link sent ove

Jun 28, 2022

A very simple tool that generates multiple spellings of a phone number (to effectively search for it using the OR operator and quotes)

phonenumberqueryconstructor A very simple tool that generates multiple writings of a phone number (to effectively search for it using the OR operator

Dec 7, 2022

A fast, vanilla JS customisable select box/text input plugin for modern browsers ⚡

choices A fast, vanilla, lightweight (~16kb gzipped 🎉 ), configurable select plugin for modern browsers. Similar to Select2 and Selectize but without

Aug 9, 2022

Format input text content when you are typing...

Cleave.js Cleave.js has a simple purpose: to help you format input text content automatically. Features Credit card number formatting Phone number for

Dec 29, 2022
Comments
  • Select Country From Dropdown

    Select Country From Dropdown

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] There should be a way to select country code from dropdown on basis of country Describe the solution you'd like A clear and concise description of what you want to happen. There should be an option to select country from a dropdown and the country code gets updated on that basis. It would be great to have this feature.

    opened by tragicmj 1
  • Please add onFormattedUpdate() callback

    Please add onFormattedUpdate() callback

    Hi! 👋

    Firstly, thanks for your work on this project! 🙂

    Today I used patch-package to patch [email protected] for the project I'm working on.

    Because the onEndEditing callback is not getting invoked until after the TextInput component loses focus, my app was attempting to save the contents of the form before the onEndEditing was called, so the formatted result was not coming in. For my use, I added another callback comparable to onValueUpdate() called onFormattedUpdate(). I also fixed a small error where you didn't provide the onValueUpdate as a useEffect dependency.

    Here is the diff that solved my problem:

    diff --git a/node_modules/react-native-intl-phone-field/src/index.tsx b/node_modules/react-native-intl-phone-field/src/index.tsx
    index af9a955..25f22d7 100644
    --- a/node_modules/react-native-intl-phone-field/src/index.tsx
    +++ b/node_modules/react-native-intl-phone-field/src/index.tsx
    @@ -16,6 +16,7 @@ export type IntlPhoneFieldProps = {
       defaultValue?: string;
       defaultFlag?: string;
       onEndEditing?: Function;
    +  onFormattedUpdate?: Function;
       onValidation?: Function;
       onValueUpdate?: Function;
       containerStyle?: object;
    @@ -30,6 +31,7 @@ let resolveFlagTimeoutId: NodeJS.Timeout;
     export default function IntlPhoneField({
       flagUndetermined = '❓',
       onEndEditing,
    +  onFormattedUpdate,
       onValidation,
       onValueUpdate,
       defaultCountry,
    @@ -112,7 +114,11 @@ export default function IntlPhoneField({
     
       useEffect(() => {
         onValueUpdate && onValueUpdate(value);
    -  }, [value]);
    +  }, [onValueUpdate, value]);
    +
    +  useEffect(() => {
    +    onFormattedUpdate && onFormattedUpdate(formatted);
    +  }, [onFormattedUpdate, formatted]);
     
       return (
         <View style={[styles.container, containerStyle]}>
    

    This issue body was partially generated by patch-package.

    opened by timothytripp 2
Releases(v0.3.0)
Owner
Ivanka Todorova
Ivanka Todorova
A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers.

Jesse Pollak 528 Dec 30, 2022
front.phone is a Javascript library that identifies, validates and formats phone numbers.

front.phone front.phone is a Javascript library that identifies, validates and formats phone numbers. Demo The main goal of this project is to create

VTEX 55 Oct 27, 2022
jquery-input-mask-phone-number.js - A simple, easy jquery format phone number mask library

jquery-input-mask-phone-number A jQuery Plugin to make masks on input field to US phone format. Quick start 1. Add latest jQuery and jquery-input-mask

Raja Rama Mohan Thavalam 12 Aug 25, 2022
A phone input component that uses intl-tel-input for Laravel Filament

Filament Phone Input This package provides a phone input component for Laravel Filament. It uses International Telephone Input to provide a dropdown o

Yusuf Kaya 24 Nov 29, 2022
Tiny JavaScript library (1kB) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Zero dependency tiny JavaScript library (1kB bytes) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Yurii De 11 Nov 8, 2022
A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

null 10 Apr 6, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A project aimed at consuming the Where is ISS? api to track the current position of International Space Station.

ISS Tracker This project aims to create a website which tracks the live position of the Internation Space Station using this API. Issues: Call the api

Microsoft Learn Student Chapter, TIET 4 Oct 21, 2022