JavaScript Library For Parsing, Formatting and Validating Phone Numbers – front.phone

Category: Form , Javascript | October 26, 2021
Author:vtex
Views Total:62 views
Official Page:Go to website
Last Update:October 26, 2021
License:MIT

Preview:

JavaScript Library For Parsing, Formatting and Validating Phone Numbers – front.phone

Description:

front.phone is an easy yet useful JavaScript library used for identifying, formatting and validation phone numbers.

Currently supports 22 countries: Argentina, Bolivia, Brazil, Canada, Chile, Colombia, Costa Rica, Ecuador, Spain, France, Guatemala, GBR, Guatemala, Korea, Mexico, Panama, Paraguay, Peru, Uruguay, United Kingdom, USA, Venezuela.

Basic usage:

Extracts information from a telephone number in international or national notation and also validate.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/USA");

// you can relax about usage of hiphens and other special characters, we'll strip 
// it down internally later ;)
var number = "4481730";
var phone = Phone.getPhoneInternational(number);
console.log(phone); // { countryCode: "1", nationalDestinationCode: "303", 
//number: "4481730", isMobile: true, isValid: true }

Validates a telephone number and then returns true or false.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/USA");

// Given a phone number in international notation
var number = "+13034481730";
var result = Phone.validate(number);
console.log(result); // true

Formats a telephone number.

var Phone = require("@vtex/phone");
var brazil = require("@vtex/phone/countries/USA");

var number = "+13034481730";
var phone = Phone.getPhoneInternational(number);
var result = Phone.format(phone, Phone.INTERNATIONAL);
console.log(result); // +1 303 448 1730

Changelog:

v4.10.8 (10/26/2021)

  • Include 2336 NDC in test regex for ARG

v4.10.7 (10/06/2021)

  • Added National destination code ‘2336’ into ARG file.

v4.10.5 (10/06/2021)

  • Add ‘663’ into MEX file

v4.10.5 (09/01/2021)

  • Add North American Numbering Plan for National Destination Code

v4.10.4 (07/28/2021)

  • Fixed Validation for VEN national destination code “424”.

v4.10.3 (07/27/2021)

  • Add ‘424’ code into VEN file

v4.10.2 (03/04/2021)

  • Add phone code ‘2984’ into ARG file

v4.10.1 (08/04/2020)

  • Updates NDC and validation regex for NANP territories.

v4.10.0 (07/22/2020)

  • Fix MEX regex

v4.9.0 (06/11/2020)

  • Add missing USA territories to NANP

v4.8.4 (05/14/2020)

  • Fix missing USA state (346 Texas)
  • Add new Mexico NDI 56

v4.8.0 (10/05/2018)

  • Added Korea and France.

v4.7.1 (06/15/2018)

  • New countries

You Might Be Interested In:


Leave a Reply