如何从react-phone-number-input软件包的select选项中删除国际选项?我试图将国家限制在只有六个。我已经添加了defaultCountry和countries属性,但它仍然允许输入其他国家的电话号码。下面是我是如何使用它的:
<PhoneInput
placeholder={placeholder}
name={name}
value={value}
onChange={onValueChange}
onBlur={handleInputBlur}
onFocus={handleInputFocus}
defaultCountry={country}
countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
/>下面是它如何在没有在属性中指定的情况下显示包含的国际选项:

如何删除国际选项。
发布于 2021-11-13 08:28:02
纪录片中提到了
defaultCountry:字符串?-如果指定了defaultCountry,则可以输入“国际”格式和“国内”格式的电话号码。以“国内”格式输入的电话号码将被解析为属于defaultCountry的电话号码。必须是支持的国家/地区代码。示例: defaultCountry="US".
源:https://www.npmjs.com/package/react-phone-number-input
<PhoneInput
placeholder={placeholder}
name={name}
value={value}
onChange={onValueChange}
onBlur={handleInputBlur}
onFocus={handleInputFocus}
defaultCountry={US}// Instead of "country" specify the country
countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
/>请阅读文档
发布于 2021-11-13 08:35:19
将国际属性设置为false,以便删除它。
通过Documentation if country is US and international property is not passed then the phone number can only be input in the "national" format for US ((213) 373-4253). But if country is "US" and international property is true then the phone number can only be input in the "international" format for US (213 373 4253) without the "country calling code" part (+1)
你的代码应该是
<PhoneInput
placeholder={placeholder}
name={name}
value={value}
international = {false}
onChange={onValueChange}
onBlur={handleInputBlur}
onFocus={handleInputFocus}
defaultCountry={country}
countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
/>https://stackoverflow.com/questions/69952555
复制相似问题