Gathering detailed insights and metrics for phone-number-validation-js
Gathering detailed insights and metrics for phone-number-validation-js
Gathering detailed insights and metrics for phone-number-validation-js
Gathering detailed insights and metrics for phone-number-validation-js
yup-phone-lite
Adds a phone number validation check to yup using libphonenumber-js.
@devmehq/sdk-js
DEV.ME SDK for JavaScript & TypeScript for Server & Browser, Compatible with Node.js & React & Vue.js & Angular
yup-phone-js
Add Yup validation for phone numbers
angular-phone-utils-lib
Angular library for phone number formatting and validation based on libphonenumber-js
npm install phone-number-validation-js
Typescript
Module System
Node Version
NPM Version
JavaScript (51.22%)
TypeScript (48.78%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
35 Commits
1 Branches
1 Contributors
Updated on Jul 02, 2025
Latest Version
1.0.4
Package Id
phone-number-validation-js@1.0.4
Unpacked Size
86.31 kB
Size
12.98 kB
File Count
6
NPM Version
10.2.4
Node Version
20.11.0
Published on
Jun 30, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Supports both JavaScript and TypeScript.
Check phone number validation with js and ts and get calling details by calling or country code
A simple, lightweight, and easy-to-implement utility to validate international phone numbers and retrieve structured information—including country name, country codes, and formatted phone numbers.
Easily check if a phone number is valid for a specific country and calling code. Just provide the country code, calling code, and phone number to get a detailed validation result.
Guideline: If you provide both the calling code and country code, do not append the calling code to the phone number itself. The phone number should only contain the local part.
This package is designed to work seamlessly across all major JavaScript and TypeScript frameworks and environments, including but not limited to:
No matter which JavaScript or TypeScript environment you're working in, this package integrates smoothly to provide reliable phone number validation.
1npm install phone-number-validation-js 2 3// or 4 5yarn add phone-number-validation-js
1import validatePhoneNumber from "phone-number-validation-js"; 2 3const result = validatePhoneNumber({ 4 callingCode: "+91", 5 countryCode: "IN", 6 phone: "9876543210", 7}); 8 9console.log(result); 10/* 11{ 12 status: true, 13 error: null, 14 message: "Phone number is valid for India (IN)", 15 data: { 16 countryCode: "IN", 17 countryCode3: "IND", 18 countryCallingCode: "91", 19 countryCallingCodeWithPlus: "+91", 20 countryName: "India", 21 phone: "9876543210", 22 formalPhoneNumber: "91 9876543210", 23 formalPhoneNumerWithPlus: "+91 9876543210", 24 }, 25} 26*/ 27 28 29## Get Country Data Example 30 31You can also retrieve country information using the `getCountryData` function: 32 33import { getCountryData } from "phone-number-validation-js"; 34 35// Example: Get country data by calling code 36const countryByCallingCode = getCountryData("+91"); 37console.log(countryByCallingCode); 38/* 39{ 40 countryCode: "IN", 41 countryCode3: "IND", 42 countryCallingCode: "91", 43 countryCallingCodeWithPlus: "+91", 44 countryName: "India" 45} 46*/ 47 48// Example: Get country data by country code 49const countryByCountryCode = getCountryData(undefined, "US"); 50console.log(countryByCountryCode); 51/* 52{ 53 countryCode: "US", 54 countryCode3: "USA", 55 countryCallingCode: "1", 56 countryCallingCodeWithPlus: "+1", 57 countryName: "United States" 58} 59*/ 60 61// Example: Neither calling code nor country code provided 62const missingParams = getCountryData(); 63console.log(missingParams); 64/* 65{ 66 status: false, 67 error: "Please provide either calling code or country code", 68 data: null 69} 70*/
The function returns an object with the following properties:
status
(boolean): Indicates if the phone number is valid.error
(string | null): Error message if validation fails, otherwise null
.message
(string): A human-readable validation message.data
(object): Contains detailed information:
countryCode
(string): ISO country code (e.g., "IN").countryCode3
(string): ISO 3-letter country code (e.g., "IND").countryCallingCode
(string): Country calling code without plus (e.g., "91").countryCallingCodeWithPlus
(string): Country calling code with plus (e.g., "+91").countryName
(string): Country name (e.g., "India").phone
(string): The validated phone number.formalPhoneNumber
(string): Formatted as "countryCallingCode phone" (e.g., "91 9876543210").formalPhoneNumerWithPlus
(string): Formatted as "+countryCallingCode phone" (e.g., "+91 9876543210").MIT
1// Example: Validate a French mobile number 2const resultFR = validatePhoneNumber({ 3 callingCode: "+33", 4 countryCode: "FR", 5 phone: "612345678", 6}); 7console.log(resultFR); 8/* 9{ 10 status: true, 11 error: null, 12 message: "Phone number is valid for France (FR)", 13 data: { 14 countryCode: "FR", 15 countryCode3: "FRA", 16 countryCallingCode: "33", 17 countryCallingCodeWithPlus: "+33", 18 countryName: "France", 19 phone: "612345678", 20 formalPhoneNumber: "33 612345678", 21 formalPhoneNumerWithPlus: "+33 612345678", 22 standardizedPhoneNumber: "+33 612345678", 23 }, 24} 25*/ 26 27// Example: All three parameters (callingCode, countryCode, phone) 28const resultIN = validatePhoneNumber({ 29 callingCode: "+91", 30 countryCode: "IN", 31 phone: "98765-43210", 32}); 33/* 34{ 35 status: true, 36 error: null, 37 message: "Phone number is valid for India (IN)", 38 data: { 39 countryCode: "IN", 40 countryCode3: "IND", 41 countryCallingCode: "91", 42 countryCallingCodeWithPlus: "+91", 43 countryName: "India", 44 phone: "98765-43210", 45 formalPhoneNumber: "91 98765-43210", 46 formalPhoneNumerWithPlus: "+91 98765-43210", 47 standardizedPhoneNumber: "+91 98765-43210", 48 }, 49} 50*/ 51 52// Example: Only callingCode and phone 53const resultGB = validatePhoneNumber({ 54 callingCode: "+44", 55 phone: "7700 900123", 56}); 57/* 58{ 59 status: true, 60 error: null, 61 message: "Phone number is valid for United Kingdom (GB)", 62 data: { 63 countryCode: "GB", 64 countryCode3: "GBR", 65 countryCallingCode: "44", 66 countryCallingCodeWithPlus: "+44", 67 countryName: "United Kingdom", 68 phone: "7700 900123", 69 formalPhoneNumber: "44 7700 900123", 70 formalPhoneNumerWithPlus: "+44 7700 900123", 71 standardizedPhoneNumber: "+44 7700 900123", 72 }, 73} 74*/ 75 76// Example: Only countryCode and phone 77const resultDE = validatePhoneNumber({ 78 countryCode: "DE", 79 phone: "1512 3456789", 80}); 81/* 82{ 83 status: true, 84 error: null, 85 message: "Phone number is valid for Germany (DE)", 86 data: { 87 countryCode: "DE", 88 countryCode3: "DEU", 89 countryCallingCode: "49", 90 countryCallingCodeWithPlus: "+49", 91 countryName: "Germany", 92 phone: "1512 3456789", 93 formalPhoneNumber: "49 1512 3456789", 94 formalPhoneNumerWithPlus: "+49 1512 3456789", 95 standardizedPhoneNumber: "+49 1512 3456789", 96 }, 97} 98*/ 99 100// Example: Only phone (auto-detects country if possible) 101const resultPhone = validatePhoneNumber({ 102 phone: "+61412345678", 103}); 104/* 105{ 106 status: true, 107 error: null, 108 message: "Phone number is valid for Australia (AU)", 109 data: { 110 countryCode: "AU", 111 countryCode3: "AUS", 112 countryCallingCode: "61", 113 countryCallingCodeWithPlus: "+61", 114 countryName: "Australia", 115 phone: "+61412345678", 116 formalPhoneNumber: "61 +61412345678", 117 formalPhoneNumerWithPlus: "+61 +61412345678", 118 standardizedPhoneNumber: "+61 +61412345678", 119 }, 120} 121*/
1// Example: Invalid country code (not recognized) 2const resultZZ = validatePhoneNumber({ 3 countryCode: "ZZ", 4 phone: "1234567890", 5}); 6/* 7{ 8 status: false, 9 error: "Invalid or unsupported country code: ZZ", 10 data: null 11} 12*/ 13 14// Example: Missing phone number 15const resultUS = validatePhoneNumber({ 16 callingCode: "+1", 17 countryCode: "US", 18}); 19/* 20{ 21 status: false, 22 error: "Phone number is required", 23 data: null 24} 25*/ 26 27// Example: Phone number too short for country 28const resultDE = validatePhoneNumber({ 29 callingCode: "+49", 30 countryCode: "DE", 31 phone: "12345", 32}); 33/* 34{ 35 status: false, 36 error: "Phone number is too short for country Germany", 37 data: null 38} 39*/ 40 41 42## Failed Validation Example 43 44 45// Example: Invalid phone number for India (does not start with 6, 7, 8, or 9) 46const resultIN = validatePhoneNumber({ 47 callingCode: "91", 48 countryCode: "IN", 49 phone: "5876543210", 50}); 51/* 52{ 53 status: false, 54 error: "Phone number must start with one of: 6, 7, 8, 9 of country India", 55 data: null 56} 57*/ 58 59// Example: Invalid calling code (not recognized) 60const result = validatePhoneNumber({ 61 callingCode: "+999", 62 phone: "1234567890", 63}); 64/* 65{ 66 status: false, 67 error: "Invalid or unsupported calling code: +999", 68 data: null 69} 70*/
phone number validation, phone validation, phone number js, phone number typescript, phone number validator, validate phone number, international phone number validation, mobile number validation, validate mobile number, phone number check, phone number verification, phone number parsing, phone number formatting, phone number formatter, phone number checker, phone validator js, phone validation npm package, phone number typescript library, phone number react validation, phone number nodejs validation, javascript phone validation, typescript phone validation, react phone validation, nodejs phone validation, nextjs phone validation, vue phone validation, svelte phone validation, angular phone validation, country code validation, calling code validation, libphonenumber alternative, lightweight phone validator, zero dependency phone validation, phone number utility library, phone input validation, form phone validation, validate user phone number, frontend phone number validation, backend phone number validation, phone number validation open source, phone number api alternative, npm phone validation package, validate international phone number, validate phone number with country code
No vulnerabilities found.
No security vulnerabilities found.