|
| 1 | +# AbstractAPI javascript-phone-validation library |
| 2 | + |
| 3 | +Integrate the powerful [Phone Validation API from Abstract](https://www.abstractapi.com/phone-validation-api) in your Javascript or NodeJS project in a few lines of code. |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +# Documentation |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +You can install **javascript-phone-validation** via npm, from our CDN, or download the source into your project. |
| 16 | + |
| 17 | +### ES6 |
| 18 | + |
| 19 | +Download and install the library from npm: |
| 20 | + |
| 21 | +``` |
| 22 | +npm install javascript-phone-validation --save |
| 23 | +``` |
| 24 | + |
| 25 | +In your project, import it and configure your `API_KEY`: |
| 26 | + |
| 27 | +```js |
| 28 | +import {AbstractPhoneValidation} from 'javascript-phone-validation' |
| 29 | + |
| 30 | +AbstractPhoneValidation.configure('API_KEY') |
| 31 | +``` |
| 32 | + |
| 33 | +### Browser, from the built file |
| 34 | + |
| 35 | +You can build the library yourself, or get the already built file from the `dist` directory and load it: |
| 36 | + |
| 37 | +```js |
| 38 | +<script src="dist/javascript-phone-validation.js"></script> |
| 39 | +<script> |
| 40 | + AbstractPhoneValidation.configure('API_KEY'); |
| 41 | + |
| 42 | + // use the library |
| 43 | +</script> |
| 44 | +``` |
| 45 | + |
| 46 | +## API key |
| 47 | + |
| 48 | +Get your API key for free and without hassle from the [Abstact website](https://app.abstractapi.com/users/signup?target=/api/phone-validation/pricing/select). |
| 49 | + |
| 50 | +## Quickstart |
| 51 | + |
| 52 | +AbstractAPI **javascript-phone-validation** library returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) so you can use one of the following approaches: |
| 53 | + |
| 54 | +### Async/Await |
| 55 | + |
| 56 | +```js |
| 57 | +async function validatePhone(number) { |
| 58 | + let response = await AbstractPhoneValidation.verify(number); |
| 59 | + console.log(response); |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### Using .then() |
| 64 | + |
| 65 | +```js |
| 66 | +function validatePhone(number) { |
| 67 | + AbstractPhoneValidation.verify(number) |
| 68 | + .then(response => { |
| 69 | + console.log(response); |
| 70 | + }) |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +## API response |
| 75 | + |
| 76 | +The API response is returned in a `IpGeolocationData` object. |
| 77 | + |
| 78 | +| PARAMETER | TYPE | DETAILS | |
| 79 | +| - | - | - | |
| 80 | +| number | String | The phone number submitted for validation and verification. | |
| 81 | +| valid | Boolean | Is true if the phone number submitted is valid. | |
| 82 | +| local_format | 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. | |
| 83 | +| international_format | String | The international format of the submitted phone number. This means appending the phone number's country code and a "+" at the beginning. | |
| 84 | +| country_name | String | The name of the country in which the phone number is registered. | |
| 85 | +| country_code | String | The country's two letter ISO 3166-1 alpha-2 code. | |
| 86 | +| country_prefix | The country's calling code prefix. | |
| 87 | +| registered_location | 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. | |
| 88 | +| carrier | String | The carrier that the number is registered with. | |
| 89 | +| line_type | String | The type of phone number. The possible values are: Landline, Mobile, Satellite, Premium, Paging, Special, Toll_Free, and Unknown. | |
| 90 | + |
| 91 | +## Detailed documentation |
| 92 | + |
| 93 | +You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/phone-validation/documentation). |
| 94 | + |
| 95 | +## Getting help |
| 96 | + |
| 97 | +If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/phone-validation/support). |
| 98 | + |
| 99 | +For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/javascript-phone-validation/issues). |
| 100 | + |
| 101 | +# Contribution |
| 102 | + |
| 103 | +Contributions are always welcome, as they improve the quality of the libraries we provide to the community. |
| 104 | + |
| 105 | +Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/javascript-phone-validation/pulls). |
| 106 | + |
| 107 | +## NPM |
| 108 | + |
| 109 | +### Installation |
| 110 | + |
| 111 | +Run `npm install` in the command line to install the dependencies. To update those dependencies you need to run `npm update`. |
| 112 | + |
| 113 | +### Building |
| 114 | + |
| 115 | +To build the library and generate the minified file in the *dist* directory, you need to run `npm run build`. |
| 116 | + |
| 117 | +To build the lib, you need to run `npm run build:lib`. |
| 118 | + |
| 119 | +### Test |
| 120 | + |
| 121 | +To run the test suite, you need to run: `npm run test`. |
0 commit comments