首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何删除React电话号码输入中的国际选项?

如何删除React电话号码输入中的国际选项?
EN

Stack Overflow用户
提问于 2021-11-13 08:07:50
回答 2查看 519关注 0票数 1

如何从react-phone-number-input软件包的select选项中删除国际选项?我试图将国家限制在只有六个。我已经添加了defaultCountrycountries属性,但它仍然允许输入其他国家的电话号码。下面是我是如何使用它的:

代码语言:javascript
复制
<PhoneInput
   placeholder={placeholder}
   name={name}
   value={value}
   onChange={onValueChange}
   onBlur={handleInputBlur}
   onFocus={handleInputFocus}
   defaultCountry={country}
   countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
 />

下面是它如何在没有在属性中指定的情况下显示包含的国际选项:

如何删除国际选项。

EN

回答 2

Stack Overflow用户

发布于 2021-11-13 08:28:02

纪录片中提到了

defaultCountry:字符串?-如果指定了defaultCountry,则可以输入“国际”格式和“国内”格式的电话号码。以“国内”格式输入的电话号码将被解析为属于defaultCountry的电话号码。必须是支持的国家/地区代码。示例: defaultCountry="US".

源:https://www.npmjs.com/package/react-phone-number-input

代码语言:javascript
复制
<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"]}
 />

请阅读文档

票数 1
EN

Stack Overflow用户

发布于 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)

你的代码应该是

代码语言:javascript
复制
<PhoneInput
   placeholder={placeholder}
   name={name}
   value={value}
   international = {false}
   onChange={onValueChange}
   onBlur={handleInputBlur}
   onFocus={handleInputFocus}
   defaultCountry={country}
   countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
 />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69952555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档