
Security News
Critical Security Vulnerability in React Server Components
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.
phone-validator-lk
Advanced tools
A lightweight Node.js library to validate, detect type, and normalize Sri Lankan mobile and landline phone numbers. Supports various input formats and standardizes them to international format (+94).
A lightweight and robust Node.js library for validating and normalizing Sri Lankan phone numbers.
+94XXXXXXXXX)npm install phone-validator-lk
or
yarn add phone-validator-lk
const { validatePhone, normalizePhone, getPhoneType } = require('phone-validator-lk');
import { validatePhone, normalizePhone, getPhoneType } from 'phone-validator-lk';
Validates a phone number and returns an object with validation results.
Parameters:
number (string): The phone number to validateReturns:
An object with the following properties:
isValid (boolean): Whether the number is a valid Sri Lankan phone numbernormalized (string|null): The normalized number in international format, or null if invalidtype (string|null): 'mobile', 'landline', or null if invalidoriginal (string): The original inputExample:
validatePhone('0712345678');
// {
// isValid: true,
// normalized: '+94712345678',
// type: 'mobile',
// original: '0712345678'
// }
validatePhone('071-234-5678');
// {
// isValid: true,
// normalized: '+94712345678',
// type: 'mobile',
// original: '071-234-5678'
// }
validatePhone('0712345');
// {
// isValid: false,
// normalized: null,
// type: null,
// original: '0712345'
// }
Normalizes a phone number to international format.
Parameters:
number (string): The phone number to normalizeReturns:
Example:
normalizePhone('0712345678'); // '+94712345678'
normalizePhone('071-234-5678'); // '+94712345678'
normalizePhone('invalid'); // null
Determines the type of phone number.
Parameters:
number (string): The phone number to checkReturns:
Example:
getPhoneType('0712345678'); // 'mobile'
getPhoneType('0112345678'); // 'landline'
getPhoneType('invalid'); // null
The library accepts the following phone number formats:
Mobile numbers in Sri Lanka have the format 07X-XXX-XXXX where X is a digit.
The package supports the following prefixes: 70, 71, 72, 74, 75, 76, 77, 78.
Examples of valid mobile number formats:
+94712345678071234567894712345678071-234-5678071 234 5678Landline numbers in Sri Lanka have the format 0XX-XXX-XXXX where XX is the area code.
Examples of valid landline number formats:
+94112345678011234567894112345678011-234-5678011 234 5678MIT
FAQs
A lightweight Node.js library to validate, detect type, and normalize Sri Lankan mobile and landline phone numbers. Supports various input formats and standardizes them to international format (+94).
We found that phone-validator-lk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
React disclosed a CVSS 10.0 RCE in React Server Components and is advising users to upgrade affected packages and frameworks to patched versions now.

Research
/Security News
We spotted a wave of auto-generated “elf-*” npm packages published every two minutes from new accounts, with simple malware variants and early takedowns underway.

Security News
TypeScript 6.0 will be the last JavaScript-based major release, as the project shifts to the TypeScript 7 native toolchain with major build speedups.