[英]react-phone-number-input validation failure
I am trying to avoid submitting react form if any input errors occurs.如果发生任何输入错误,我试图避免提交反应表单。 But only for the phone number input field's validations which is handled by
react-phone-number-input
package I am having issues because it allows to submit even for invalid inputs.但仅对于由
react-phone-number-input
package 处理的电话号码输入字段的验证,我遇到了问题,因为它甚至允许提交无效输入。 So I added validate
property in rules object prop.所以我在规则 object prop 中添加了
validate
属性。 But it throws me parsePhoneNumber.js:18 Uncaught (in promise) TypeError: A text for parsing must be a string.
但它抛出我
parsePhoneNumber.js:18 Uncaught (in promise) TypeError: A text for parsing must be a string.
My attempt is as below.我的尝试如下。
<Controller
name="phoneNum"
render={({ field }) => (
<SPhone
label={Properties.TEL}
{...field}
error={errors.phoneNum && true}
helperText={errors.phoneNum && errors.phoneNum.msg}/>
)}
control={control}
defaultValue=""
rules={{validate: (value) => isValidPhoneNumber(value)}}
/>
So what is the correct way to assign the rules prop to satisfy with the above phone number validation?那么分配规则道具以满足上述电话号码验证的正确方法是什么?
<Controller
name="phoneNum"
render={({ field }) => (
<SPhone
label={Properties.TEL}
{...field}
error={errors.phoneNum && true}
helperText={errors.phoneNum && errors.phoneNum.msg}/>
)}
control={control}
defaultValue=""
rules={{validate: (value) => isValidPhoneNumber(`${value}`)}}
/>
template string works for me.模板字符串对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.