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

Category: Form , Javascript | February 17, 2025
Author:vtex
Views Total:22 views
Official Page:Go to website
Last Update:February 17, 2025
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.20.0 (02/17/2025)

  • Added Angola (‘AGO’) country rules.
  • Added Portugal (‘PRT’) country rules.

v4.19.5 (02/26/2024)

  • CI/CD pipeline from Jenkins to DK.

v4.19.4 (02/27/2024)

  • Fixed Indonesia (‘IDN’) phone rules.

v4.19.3 (07/27/2023)

  • Update IDN phone rules.

v4.19.2 (06/28/2023)

  • Fix Indonesia (‘IDN’) phone rules.

v4.19.1 (05/31/2023)

  • Fix Honduras country rules

v4.19.0 (05/26/2023)

  • Bugfixes

v4.18.0 (05/25/2023)

  • Updates

v4.17.11 (05/11/2023)

  • Bugfixes

v4.17.10 (04/13/2023)

  • Phone rules to accept slash when entering a number

v4.17.9 (03/11/2023)

  • Fix Australia phone format

v4.17.8 (03/02/2023)

  • Fix AUS country rules

v4.17.7 (01/27/2023)

  • Add new area codes for ARG and MEX

v4.17.6 (01/07/2023)

  • Fix ROU country rules

v4.17.5 (12/07/2022)

  • Fix MEX and add ROU, SAU, ARE and GRC country rules

v4.17.4 (10/20/2022)

  • Fix FRA numbers

v4.17.3 (08/17/2022)

  • Fixed: France (‘FRA’) country rules to remove extra zero before mobile numbers.

v4.17.2 (07/27/2022)

  • Add AUS and NZL country rules

v4.17.0 (07/23/2022)

  • New country rules for CZE, IDN and SVK

v4.16.0 (05/27/2022)

  • Add Italy phone rules

v4.15.2 (05/05/2022)

  • Fix NANP regex for domenican republic phone numbers

v4.15.1 (03/25/2022)

  • Dominican Republic phone number rules (‘DOM’, ‘NANP’)

v4.15.0 (02/24/2022)

  • Update

v4.15.0 (02/24/2022)

  • Update

v4.14.0 (02/18/2022)

  • Added India phone rules.
  • Fixed Iraq phone rules.

v4.13.1 (02/10/2022)

  • fix SGP and COL rules

v4.13.0 (01/28/2022)

  • Update

v4.11.0 (01/20/2022)

  • Added Iraq configuration.

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