Professional Phone Number Validation Library

Phone Number Validator JS

High-performance phone validation library with geocoding, carrier mapping, timezone detection, LRU caching, and full TypeScript support. Sub-millisecond lookups for Node.js applications.

GitHubNPM

Key Features

Phone Number Validation

Validate phone numbers for format and validity across all countries with TypeScript support

Carrier Detection

Identify the carrier/operator for mobile and landline numbers worldwide

Geocoding

Get precise geographic location including city and region for any phone number

Timezone Mapping

Retrieve accurate timezone information for international calling and scheduling

High Performance

LRU caching with O(1) complexity, sub-millisecond lookups after initial load

TypeScript First

Built with TypeScript for complete type safety and excellent IDE support

Installation

NPM
npm install @devmehq/phone-number-validator-js
Yarn
yarn add @devmehq/phone-number-validator-js

Code Examples

Basic Phone Validation

import { parsePhoneNumberFromString } from '@devmehq/phone-number-validator-js';

// Parse and validate a phone number
const phoneNumber = parsePhoneNumberFromString('+14155552671');

if (phoneNumber) {
  console.log(phoneNumber.isValid());        // true
  console.log(phoneNumber.country);          // 'US'
  console.log(phoneNumber.formatNational()); // '(415) 555-2671'
  console.log(phoneNumber.formatInternational()); // '+1 415 555 2671'
  console.log(phoneNumber.getType());        // 'MOBILE' or 'FIXED_LINE'
}

Carrier and Location Information

import { geocoder, carrier, timezones, parsePhoneNumberFromString } from '@devmehq/phone-number-validator-js';

// Get carrier information
const mobileNumber = parsePhoneNumberFromString('+8619912345678');
const carrierName = carrier(mobileNumber, 'en');
console.log(carrierName); // 'China Telecom'

// Get location information
const fixedLineNumber = parsePhoneNumberFromString('+41431234567');
const location = geocoder(fixedLineNumber, 'en');
console.log(location); // 'Zurich'

// Get timezone information
const phoneNumber = parsePhoneNumberFromString('+12125551234');
const tzList = timezones(phoneNumber);
console.log(tzList); // ['America/New_York']

International Format Support

import { parsePhoneNumberFromString } from '@devmehq/phone-number-validator-js';

// Parse numbers from different countries
const usNumber = parsePhoneNumberFromString('+1 415 555 2671');
const ukNumber = parsePhoneNumberFromString('+44 20 7123 1234');
const jpNumber = parsePhoneNumberFromString('+81 3-1234-5678');

// Format for display
console.log(usNumber.formatNational());  // '(415) 555-2671'
console.log(ukNumber.formatNational());  // '020 7123 1234'
console.log(jpNumber.formatNational());  // '03-1234-5678'

// Get country information
console.log(usNumber.country);  // 'US'
console.log(ukNumber.country);  // 'GB'
console.log(jpNumber.country);  // 'JP'

// Check number types
console.log(usNumber.getType());  // 'MOBILE' or 'FIXED_LINE'
console.log(ukNumber.getType());  // 'FIXED_LINE'
console.log(jpNumber.getType());  // 'FIXED_LINE'

Form Validation Example

// React form with phone validation
const PhoneForm = () => {
  const [phone, setPhone] = useState('');
  const [validation, setValidation] = useState(null);

  const validatePhone = (value) => {
    try {
      const phoneNumber = parsePhoneNumberFromString(value);
      
      if (phoneNumber && phoneNumber.isValid()) {
        const info = {
          valid: true,
          formatted: phoneNumber.formatInternational(),
          country: phoneNumber.country,
          type: phoneNumber.getType(),
          carrier: carrier(phoneNumber, 'en'),
          location: geocoder(phoneNumber, 'en'),
          timezone: timezones(phoneNumber)
        };
        setValidation(info);
      } else {
        setValidation({ valid: false, error: 'Invalid phone number' });
      }
    } catch (error) {
      setValidation({ valid: false, error: error.message });
    }
  };

  return (
    <div>
      <input
        type="tel"
        value={phone}
        onChange={(e) => {
          setPhone(e.target.value);
          validatePhone(e.target.value);
        }}
        placeholder="+1 415 555 2671"
      />
      {validation && (
        <div>
          {validation.valid ? (
            <>
              ✅ Valid: {validation.formatted}
              Country: {validation.country}
              Type: {validation.type}
              Carrier: {validation.carrier}
            </>
          ) : (
            <>❌ {validation.error}</>
          )}
        </div>
      )}
    </div>
  );
};

API Reference

Main Functions

parsePhoneNumberFromString(text, defaultCountry?)

Parse a phone number from a string. Returns a PhoneNumber object or undefined.

Returns: PhoneNumber | undefined

geocoder(phoneNumber, locale?)

Get geographic location information for a phone number.

Returns: string (location name)

carrier(phoneNumber, locale?)

Get carrier/operator information for a phone number.

Returns: string (carrier name)

timezones(phoneNumber)

Get timezone(s) associated with a phone number.

Returns: string[] (timezone identifiers)

PhoneNumber Object Methods

  • isValid() - Check if the number is valid
  • formatNational() - Format for national display
  • formatInternational() - Format for international display
  • getType() - Get number type (MOBILE, FIXED_LINE, etc.)
  • getCountry() - Get ISO country code
  • getNationalNumber() - Get national number portion
  • getURI() - Get tel: URI format

Use Cases

SMS campaign validation and optimization

Preventing spam and fake phone number registrations

E-commerce checkout and order verification

Website and mobile app form validation

Fraud prevention and security screening

CRM data quality and lead validation

Call center routing and optimization

International business communications

Two-factor authentication systems

Customer identity verification

Performance Metrics

<1ms

Lookup time after initial load

O(1)

Cache complexity

LRU

Intelligent cache eviction

Technical Details

Performance Features

  • High-performance LRU caching system
  • Binary JSON files for efficient data storage
  • Prefix-based search optimization
  • Sub-millisecond response times
  • Minimal memory footprint

Developer Experience

  • Full TypeScript support with strict typing
  • Comprehensive JSDoc documentation
  • Multiple locale support with fallback
  • Zero external dependencies
  • Global phone number coverage

Simple, Transparent Pricing

Choose the perfect plan for your phone validation needs. All plans include full API access, TypeScript support, and regular updates.

Startup

Perfect for small businesses and MVPs

$39/month
  • Up to 100,000 validations/month
  • All 250+ countries
  • Email support
  • Commercial use license
Get Started
MOST POPULAR

Business

For growing companies with higher volume

$119/month
  • Up to 500,000 validations/month
  • All validation features
  • Priority email support
  • Commercial use license
  • Bulk validation with LRU cache
Get Started

Enterprise

For large-scale applications

$299/month
  • Unlimited validations
  • All validation features
  • 24/7 priority support
  • Commercial use license
  • Custom integration support
  • SLA guarantee
Contact Sales

One-Time License

Perpetual license for a single product - no recurring fees

$2,499

one-time payment

Purchase License

Why Choose Our Phone Validator?

vs. Google libphonenumber

✓ 10x faster with LRU caching

✓ TypeScript-first design

✓ Lighter bundle size

vs. API Services

✓ No network latency

✓ Works offline

✓ No per-request costs

Performance

✓ < 1ms validation

✓ O(1) complexity

✓ Zero dependencies

Licensing Terms

Community Edition (Free)

This library is distributed under the Business Source License (BSL) 1.1. You can use it freely for:

  • Non-production environments
  • Development and testing
  • Open source projects
  • Educational purposes

Commercial License Required For:

  • Production use in commercial applications
  • SaaS products and services
  • Revenue-generating projects
  • Enterprise deployments

Questions about licensing? Contact us at sales@dev.me

Phone Number Validator JS - Advanced Phone Validation Library | Dev.me | dev.me