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

How do i get only the phone number and not the country code or how can i extracct the phone number from this response? #198

Open
shabanaqureshi opened this issue May 31, 2023 · 1 comment

Comments

@shabanaqureshi
Copy link

Hello,
I am using the following library to extract the phone number of the user. I want to enable auto filling of mobile number,
I am using the PhoneFieldHint library, am able to get the phone number with the country code, but i want to get only the phone number.
Question: How do i get only the phone number and not the country code or how can i extracct the phone number from this response?

@LakshayDCoder
Copy link

I also had the same problem so I just extracted the last 10 digits of the string that I got from the autofil hint. Below is the code for the same.

phoneController.text = extractLast10Digits(phone);

  String extractLast10Digits(String input) {
    String digitsOnly = input.replaceAll(RegExp(r'[^0-9]'), '');
    if (digitsOnly.length >= 10) {
      return digitsOnly.substring(digitsOnly.length - 10);
    } else {
      return digitsOnly;
    }
  }

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

2 participants