thegamenicorus / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
394 stars 447 forks source link

Add autoFormat option to PhoneInput #70

Closed jling90 closed 5 years ago

jling90 commented 5 years ago

Adds an 'autoFormat' option to PhoneInput which allows phone numbers to be formatted as they are entered.

# Before After
before after
kelvinoshea commented 5 years ago

this is awesome

brodgaggi commented 5 years ago

i never thought i would see the day.

sdcoffey commented 5 years ago

This is awesome! Would love to see this merged!

MacKentoch commented 5 years ago

Seems nice, please ship it 🙏

brunitob commented 5 years ago

Any news?

mperumalswamy commented 5 years ago

Any news when would it be merged so as to use it??

jling90 commented 5 years ago

image

gif

MacKentoch commented 5 years ago

Tired of waiting I forked this PR and adapted to my needs: automatic national phone number format:

This is a 1 hour derived library so don't expect it to cover all needs:

brunitob commented 5 years ago

Image of bob

michaelVictoriaDev commented 5 years ago

PLEASE we need this feature :)

michaelVictoriaDev commented 5 years ago

@thegamenicorus please Accept the PR :)

gucolin commented 5 years ago

I ended up just pasting the fix into my component, make sure you do clear() at the end though.

  onCountrySelected = (country) => {
    this.phoneInput.selectCountry(country.cca2.toLowerCase());
    this.phoneNumberFormatter = new asYouTypeFormatter(country.cca2);
    this.setState({
      cca2: country.cca2
    });
  }

  onPhoneNumberChanged = (phoneNumber) => {
    let formattedNumber;

    phoneNumber.replace(/-/g, '')
      .replace(/ /g, '')
      .split('')
      .forEach(n => formatted = this.phoneNumberFormatter.inputDigit(n));

    this.setState({
      phoneNumber: formattedNumber
    });

    this.phoneNumberFormatter.clear();
  }
rafaismyname commented 5 years ago

@thegamenicorus are you alive?

michaelVictoriaDev commented 5 years ago

@thegamenicorus THANK YOU!!!!!!

Zakyyy commented 3 years ago

is it merged? @thegamenicorus