简体   繁体   English

反应电话号码验证

[英]react phone number validation

I am using joi-phone-numbe r library for phone number validation.我正在使用 joi -phone-numbe r 库进行电话号码验证。

This is sample code for react am trying这是我正在尝试的反应示例代码

import Joi from 'joi';
import cNumber from 'joi-phone-number';
const myJoi = Joi.extend(cNumber);

schema = {
        phone: myJoi.string().phoneNumber({defaultCountry: 'US',format: 'international'})
} 

The problem is it validates only first two digits after that it shows the number is correct问题是它只验证前两位数,然后显示数字是正确的

Example
09 Invalid
999 Valid

So how am supposing to use this with react.那么我应该如何将其与 React 一起使用。 Mine goal is here to check country code too with valid phone number.我的目标是在这里也用有效的电话号码检查国家代码。

Not sure, but can you try this?不确定,但你能试试这个吗?

import simpleJoi from "joi";
const Joi = simpleJoi.extend(require("joi-phone-number"));

schema = {
  phone: Joi.string().phoneNumber({defaultCountry: 'US',format:'international'})
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM