es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
17 lines (16 loc) • 764 B
TypeScript
/**
* Validates if a string is a valid phone number according to specified format.
* @param {string} phone - The phone number to validate.
* @param {'E164' | 'NANP'} format - The format to validate against (E164 or North American Number Plan).
* @returns {boolean} True if the phone number is valid, false otherwise.
* @example
* // E164 format
* console.log(isPhoneNumber('+14155552671')); // true
* console.log(isPhoneNumber('+1415555267')); // false
*
* // NANP format
* console.log(isPhoneNumber('(415) 555-2671', 'NANP')); // true
* console.log(isPhoneNumber('415-555-2671', 'NANP')); // true
* console.log(isPhoneNumber('4155552671', 'NANP')); // true
*/
export declare function isPhoneNumber(phone: string, format?: 'E164' | 'NANP'): boolean;