High-performance phone validation library with geocoding, carrier mapping, timezone detection, LRU caching, and full TypeScript support. Sub-millisecond lookups for Node.js applications.
Validate phone numbers for format and validity across all countries with TypeScript support
Identify the carrier/operator for mobile and landline numbers worldwide
Get precise geographic location including city and region for any phone number
Retrieve accurate timezone information for international calling and scheduling
LRU caching with O(1) complexity, sub-millisecond lookups after initial load
Built with TypeScript for complete type safety and excellent IDE support
npm install @devmehq/phone-number-validator-js
yarn add @devmehq/phone-number-validator-js
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'
}
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']
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'
// 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>
);
};
Parse a phone number from a string. Returns a PhoneNumber object or undefined.
Returns: PhoneNumber | undefined
Get geographic location information for a phone number.
Returns: string (location name)
Get carrier/operator information for a phone number.
Returns: string (carrier name)
Get timezone(s) associated with a phone number.
Returns: string[] (timezone identifiers)
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
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
Lookup time after initial load
Cache complexity
Intelligent cache eviction
Choose the perfect plan for your phone validation needs. All plans include full API access, TypeScript support, and regular updates.
Perfect for small businesses and MVPs
For growing companies with higher volume
For large-scale applications
Perpetual license for a single product - no recurring fees
one-time payment
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
This library is distributed under the Business Source License (BSL) 1.1. You can use it freely for:
Questions about licensing? Contact us at sales@dev.me