Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to only include one country code and no dropdown using react-native-phone-number-input?

<PhoneInput
        ref={phoneInput}
        defaultValue={phoneNumber}
        defaultCode="GB"
        layout="second"
        withShadow
        filterProps
        autoFocus
        disableArrowIcon
        containerStyle={styles.phoneContainer}
        textContainerStyle={styles.textInput}
        onChangeFormattedText={(text) => {
          setphoneNumber(text);
        }}
      />

I am using the library ‘react-native-phone-number-input’ so a user can easily enter their number with the country code already there. Right now our app only allows users from the UK so I was wondering if there is a way to only have the ‘GB’ country code with no other country codes available?

I disabled the arrow icon but the user is still able to click on the country code and then given the option to select another.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Hey you can do via passing countryPickerProps as.

<PhoneInput
        ref={phoneInput}
        defaultValue={phoneNumber}
        defaultCode="GB"
        layout="second"
        withShadow
        filterProps
        autoFocus
        disableArrowIcon
        containerStyle={styles.phoneContainer}
        textContainerStyle={styles.textInput}
        onChangeFormattedText={(text) => {
          setphoneNumber(text);
        }}
        countryPickerProps={{
          countryCodes: ['GB'],
        }}
      />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading