Saturday, April 20, 2024
Bootstrap 4Bootstrap 4.5Reactjs

Reactjs International Telephone Input

Reactjs International Telephone Input

Hello friends, welcome back to my blog. Today in this blog post, I am going to show you, Reactjs International Telephone Input.

In this post, we will do below steps:

  1. Add country code and courting flag to telephone input in react js.
  2. Set and get the telephone input.
  3. Countries Check.

Reactjs International Telephone Input
Reactjs International Telephone Input
Reactjs International Telephone Input with few countries
Reactjs International Telephone Input with few countries

For reactjs new comers, please check the below link:

Reactjs Basic Tutorials

Friends now I proceed onwards and here is the working code snippet and please use this carefully to avoid the mistakes:

1. Firstly, we need fresh reactjs setup and for that, we need to run below commands into out terminal and also we should have latest node version installed on our system:

npx create-react-app reacttemplate

cd reacttemplate

npm start

2. Now we need to run below commands into our project terminal to get bootstrap and related modules into our reactjs application:

npm install bootstrap --save

npm install react-phone-input-2 --save

npm start //For start project again

3. Finally for the main output, we need to add below code into our reacttemplate/src/App.js file or if you have fresh setup then you can replace reacttemplate/src/App.js file code with below code:

import React from "react";

import './App.css'
import 'bootstrap/dist/css/bootstrap.min.css';

//Importing input tepp modules
import PhoneInput from 'react-phone-input-2'
import 'react-phone-input-2/lib/style.css'

class App extends React.Component {
 //setting default phone number
 constructor(props) {
  this.state = {phone: "13338965474"};

  render() {
    return (
      <div className="main_container">
        <div class="container">
          <p>Current Phone Number is : {}</p>
        <div class="form-group">
          onChange={phone => this.setState({ phone })}

               <div className="form-group">
                 <label>Only Few Countries Available</label>
                onlyCountries={['gr', 'fr', 'us']}

export default App;

Now we are done friends. If you have any kind of query or suggestion or any requirement then feel free to comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.



the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.