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

country code #79

Open
kavin06 opened this issue Mar 30, 2019 · 5 comments
Open

country code #79

kavin06 opened this issue Mar 30, 2019 · 5 comments

Comments

@kavin06
Copy link

kavin06 commented Mar 30, 2019

Unable to get country code separately.How to get country code? Any help.Thanks in Advance

@BryanLovesToCode
Copy link

BryanLovesToCode commented Apr 3, 2019

This is how I would do it (Swift 4+)

let countryCode = flagPhoneNumberTextField.getFormattedPhoneNumber(format: .International)?.split(separator: " ")

 if countryCode?.count ?? 0 > 0 {
        if countryCode![0] == "+33" {
              print("this is a french phone code")
        }
    }

or

if let countryCode = flagPhoneNumberTextField.getFormattedPhoneNumber(format: .International)?.split(separator: " ") {
        if countryCode![0] == "+33" {
              print("this is a french phone code")
        }
    }

Tell me if it works !

@marcmatta
Copy link

marcmatta commented May 19, 2019

Hi @grifas,

Maybe making private var nbPhoneNumber: NBPhoneNumber? as public can resolve this issue?

or maybe a new property like this:

var rawCountryCode: String {
return textField.phoneCodeTextField.text
}

Cheers,

@marcmatta
Copy link

This is how I would do it (Swift 4+)

let countryCode = flagPhoneNumberTextField.getFormattedPhoneNumber(format: .International)?.split(separator: " ")

 if countryCode?.count ?? 0 > 0 {
        if countryCode![0] == "+33" {
              print("this is a french phone code")
        }
    }

or

if let countryCode = flagPhoneNumberTextField.getFormattedPhoneNumber(format: .International)?.split(separator: " ") {
        if countryCode![0] == "+33" {
              print("this is a french phone code")
        }
    }

Tell me if it works !

@BryanLovesToCode this does not work if the phone number is not valid.

@kavin06
Copy link
Author

kavin06 commented May 20, 2019

@BryanLovesToCode Still its not working.

@sameeh0946
Copy link

@kavin06
What @BryanLovesToCode has given works. I'd like to make it clear for you

        let input = phoneNumberTextField.getFormattedPhoneNumber(format: .International)?.split(separator: " ")
        let countryPhoneCode = input![0]

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

4 participants