@abstractapi/javascript-phone-validation 中文文档教程

发布于 3年前 浏览 23 项目主页 更新于 3年前

AbstractAPI javascript-phone-validation library

通过几行代码将功能强大的Abstract 中的电话验证 API 集成到您的 Javascript 或 NodeJS 项目中。

Abstract 的电话号码验证和验证 API 是一种快速、轻量级、现代和 RESTful JSON API,用于确定来自 190 多个国家/地区的电话号码的有效性和其他详细信息。

使用起来非常简单:您只需提交您的 API 密钥和电话号码,API 将响应其有效性评估,以及其他详细信息,如运营商详细信息、线路类型、地区和城市详细信息等.

验证和验证电话号码是减少网站或应用程序中出现低质量数据和欺诈或风险用户的机会的关键步骤。

Documentation

Installation

您可以从我们的 CDN 通过 npm 安装 javascript-phone-validation,或者将源代码下载到您的项目中。

ES6

从 npm 下载并安装库:

npm install @abstractapi/javascript-phone-validation --save

在你的项目中,导入它并配置你的 API_KEY

import {AbstractPhoneValidation} from 'javascript-phone-validation'

AbstractPhoneValidation.configure('API_KEY')

Browser, from the CDN

你可以让浏览器通过 jsDeliver CDN 从最近的位置下载库:

<script src="https://cdn.jsdelivr.net/npm/@abstractapi/javascript-core@latest/dist/javascript-core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@abstractapi/javascript-phone-validation@latest/dist/javascript-phone-validation.js"></script>
<script>
    AbstractEmailValidation.configure('API_KEY');

    // use the library
</script>

Browser, from the built file

你可以自己构建库,或者从 dist 目录获取已经构建的文件并加载它:

<script src="dist/javascript-phone-validation.js"></script>
<script>
    AbstractPhoneValidation.configure('API_KEY');

    // use the library
</script>

API key

抽象网站

Quickstart

AbstractAPI javascript-phone-validation 库返回一个 Promise< /a> 因此您可以使用以下方法之一:

Async/Await

async function validatePhone(number) {
  let response = await AbstractPhoneValidation.verify(number);
  console.log(response);
}

Using .then()

function validatePhone(number) {
  AbstractPhoneValidation.verify(number)
    .then(response => {
      console.log(response);
    })
}

API response

API 响应在 IpGeolocationData 对象中返回。

| 参数 | 类型 | 详情 | | - | - | - | | 编号 | 字符串 | 提交验证和验证的电话号码。 | | 有效 | 布尔值 | 如果提交的电话号码有效,则为真。 | | 本地格式 | 字符串 | 提交的电话号码的本地或国家格式。 例如,它会删除任何国际格式,例如美国的“+1”。 | | 国际格式 | 字符串 | 提交的电话号码的国际格式。 这意味着在开头附加电话号码的国家代码和“+”。 | | 国家名称 | 字符串 | 电话号码注册所在国家/地区的名称。 | | 国家/地区代码 | 字符串 | 该国家/地区的两个字母 ISO 3166-1 alpha-2 代码。 | | 国家/地区前缀 | 国家的呼叫代码前缀。 | | 注册地点 | 字符串 | 我们的数据中提供尽可能多的位置详细信息。 这可以包括地区、州/省,在某些情况下甚至包括城市。 | | 承运人 | 字符串 | 注册号码的运营商。 | | 行类型 | 字符串 | 电话号码的类型。 可能的值有:固定电话、移动电话、卫星电话、Premium、Paging、Special、TollFree 和 Unknown。 |

Detailed documentation

您可以在 Abstract 帮助页面 中找到更多信息和请求示例。

Getting help

如果您在安装或使用库方面需要帮助,请联系 Abstract 的支持

对于错误报告和功能建议,请使用此存储库问题页面

Contribution

贡献总是受欢迎的,因为它们提高了我们提供给社区的图书馆的质量。

请提供相应单元测试涵盖的更改,并将它们发布到拉取请求页面

NPM

Installation

在命令行中运行 npm install 以安装依赖项。 要更新这些依赖项,您需要运行 npm update

Building

要构建库并在 dist 目录中生成缩小文件,您需要运行 npm run build

要构建库,您需要运行 npm run build:lib

Test

要运行测试套件,您需要运行:npm run test

AbstractAPI javascript-phone-validation library

Integrate the powerful Phone Validation API from Abstract in your Javascript or NodeJS project in a few lines of code.

Abstract's Phone Number Validation and Verification API is a fast, lightweight, modern, and RESTful JSON API for determining the validity and other details of phone numbers from over 190 countries.

It's very simple to use: you only need to submit your API key and a phone number, and the API will respond as assessment of its validity, as well as additional details like the carrier details, line type, region and city details, and more.

Validating and verifying phone numbers is a critical step to reducing the chances of low quality data and fraudulent or risky users in your website or application.

Documentation

Installation

You can install javascript-phone-validation via npm, from our CDN, or download the source into your project.

ES6

Download and install the library from npm:

npm install @abstractapi/javascript-phone-validation --save

In your project, import it and configure your API_KEY:

import {AbstractPhoneValidation} from 'javascript-phone-validation'

AbstractPhoneValidation.configure('API_KEY')

Browser, from the CDN

You can have the browser download the library from its closest location through jsDeliver CDN:

<script src="https://cdn.jsdelivr.net/npm/@abstractapi/javascript-core@latest/dist/javascript-core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@abstractapi/javascript-phone-validation@latest/dist/javascript-phone-validation.js"></script>
<script>
    AbstractEmailValidation.configure('API_KEY');

    // use the library
</script>

Browser, from the built file

You can build the library yourself, or get the already built file from the dist directory and load it:

<script src="dist/javascript-phone-validation.js"></script>
<script>
    AbstractPhoneValidation.configure('API_KEY');

    // use the library
</script>

API key

Get your API key for free and without hassle from the Abstact website.

Quickstart

AbstractAPI javascript-phone-validation library returns a Promise so you can use one of the following approaches:

Async/Await

async function validatePhone(number) {
  let response = await AbstractPhoneValidation.verify(number);
  console.log(response);
}

Using .then()

function validatePhone(number) {
  AbstractPhoneValidation.verify(number)
    .then(response => {
      console.log(response);
    })
}

API response

The API response is returned in a IpGeolocationData object.

| PARAMETER | TYPE | DETAILS | | - | - | - | | number | String | The phone number submitted for validation and verification. | | valid | Boolean | Is true if the phone number submitted is valid. | | localformat | String | The local or national format of the submitted phone number. For example, it removes any international formatting, such as "+1" in the case of the US. | | internationalformat | String | The international format of the submitted phone number. This means appending the phone number's country code and a "+" at the beginning. | | countryname | String | The name of the country in which the phone number is registered. | | countrycode | String | The country's two letter ISO 3166-1 alpha-2 code. | | countryprefix | The country's calling code prefix. | | registeredlocation | String | As much location details as are available from our data. This can include the region, state / province, and in some cases down to the city. | | carrier | String | The carrier that the number is registered with. | | linetype | String | The type of phone number. The possible values are: Landline, Mobile, Satellite, Premium, Paging, Special, TollFree, and Unknown. |

Detailed documentation

You will find additional information and request examples in the Abstract help page.

Getting help

If you need help installing or using the library, please contact Abstract's Support.

For bug report and feature suggestion, please use this repository issues page.

Contribution

Contributions are always welcome, as they improve the quality of the libraries we provide to the community.

Please provide your changes covered by the appropriate unit tests, and post them in the pull requests page.

NPM

Installation

Run npm install in the command line to install the dependencies. To update those dependencies you need to run npm update.

Building

To build the library and generate the minified file in the dist directory, you need to run npm run build.

To build the lib, you need to run npm run build:lib.

Test

To run the test suite, you need to run: npm run test.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文