Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to put a gap between country code and phone number #33

Open
ranarashidsadiq opened this issue Mar 14, 2018 · 3 comments

Comments

@ranarashidsadiq
Copy link

I searched and found there is no way to put a blank space between country code and actual phone number.. I want (+xx xxxxxxxxxx) but it allows me to go with this (+xxxxxxxxxxxx)..

@giacomocerquone
Copy link

giacomocerquone commented May 29, 2018

I'm about to use this module too and I need a similar thing.
A way to force this behaviour is to use this component just as the prefix input and then use another text input for the phone number

But I get you it might be an overkill
We could add a flagOffset and prefixOffset prop.
What do you think? @thegamenicorus

@ujwal-setlur
Copy link

Yup, need this too. Will provide a PR.

@ujwal-setlur
Copy link

ujwal-setlur commented Jun 11, 2018

you can do it without hacking the code, actually. Just use libphonenumber-js and the onChangePhoneNumber callback:

npm install libphonenumber-js --save

import React from "react";
import { StyleSheet, View } from "react-native";
import PhoneInput from "react-native-phone-input";
import { formatNumber } from "libphonenumber-js";

type Props = {};

export default class Login extends React.Component<Props> {

  constructor(props) {
    super(props);

    this.onChangePhoneNumber = this.onChangePhoneNumber.bind(this);

    this.state = {
      phoneNumber: ""
    };
  }

  onChangePhoneNumber(newNumber: string) {
    console.log("Setting new number to " + newNumber);
    this.setState({
      phoneNumber: formatNumber(newNumber, "International")
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <PhoneInput
          ref={(ref) => {
                 this.phone = ref;
               }}
          onPressFlag={this.onPressFlag}
          onChangePhoneNumber={this.onChangePhoneNumber}
          value={this.state.phoneNumber}
        />
      </View>
      );
  }
}

With this, you can format the number in all the ways that libphonenumber-js does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants