global-phone-validator 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -46
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# global-phone-validator
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A comprehensive Node.js + TypeScript package for validating phone numbers worldwide. Supports **all countries** with **country-specific validation rules** for 50+ major countries. Handles international formats (+CC), 0-prefixed, and plain digits. Includes mobile/landline detection for India and returns standardized E.164 format.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- ✅ **
|
|
7
|
+
- ✅ **True Global Validation**: Validates phone numbers for **all countries** with country-specific rules for 50+ major countries
|
|
8
|
+
- ✅ **Country-Specific Rules**: Accurate validation for US, UK, Germany, France, Australia, Brazil, China, Japan, India, and 40+ more countries
|
|
8
9
|
- ✅ **Multiple Formats**: Handles international format (+CC), 0-prefixed, and plain digit formats
|
|
9
10
|
- ✅ **India-Specific**: Mobile vs landline detection for Indian phone numbers
|
|
10
|
-
- ✅ **Standardized Output**: Returns E.164 format (+CCNNNNNNNNN)
|
|
11
|
+
- ✅ **Standardized Output**: Returns E.164 format (+CCNNNNNNNNN) with country information
|
|
11
12
|
- ✅ **TypeScript**: Fully typed with TypeScript definitions
|
|
12
13
|
- ✅ **Zero Dependencies**: No external dependencies required
|
|
14
|
+
- ✅ **ITU-T E.164 Compliant**: Follows international telecommunication standards
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
@@ -19,15 +21,50 @@ npm install global-phone-validator
|
|
|
19
21
|
yarn add global-phone-validator
|
|
20
22
|
```
|
|
21
23
|
|
|
24
|
+
## Try It Online
|
|
25
|
+
|
|
26
|
+
Test the package directly in your browser with RunKit:
|
|
27
|
+
|
|
28
|
+
**[▶️ Try on RunKit](https://npm.runkit.com/global-phone-validator)**
|
|
29
|
+
|
|
30
|
+
> **Note:** If you get a 503 error, RunKit may be temporarily unavailable or the latest version may still be indexing. Try again in a few minutes, or test locally using the code below.
|
|
31
|
+
|
|
32
|
+
### Quick Test Code
|
|
33
|
+
|
|
34
|
+
You can paste this code in RunKit or run it locally:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
const { validatePhoneNumber } = require("global-phone-validator");
|
|
38
|
+
|
|
39
|
+
// Test various countries
|
|
40
|
+
console.log(validatePhoneNumber("+91 98765 43210")); // India - Mobile
|
|
41
|
+
console.log(validatePhoneNumber("+1 555 123 4567")); // USA
|
|
42
|
+
console.log(validatePhoneNumber("+44 20 7946 0958")); // UK
|
|
43
|
+
console.log(validatePhoneNumber("+49 176 77274194")); // Germany - Mobile
|
|
44
|
+
console.log(validatePhoneNumber("+49 30 12345678")); // Germany - Landline
|
|
45
|
+
console.log(validatePhoneNumber("+61 2 1234 5678")); // Australia
|
|
46
|
+
console.log(validatePhoneNumber("+86 138 0013 8000")); // China
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Test Locally
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Install the package
|
|
53
|
+
npm install global-phone-validator
|
|
54
|
+
|
|
55
|
+
# Create a test file
|
|
56
|
+
node -e "const {validatePhoneNumber} = require('global-phone-validator'); console.log(validatePhoneNumber('+91 98765 43210'));"
|
|
57
|
+
```
|
|
58
|
+
|
|
22
59
|
## Usage
|
|
23
60
|
|
|
24
61
|
### Basic Validation
|
|
25
62
|
|
|
26
63
|
```typescript
|
|
27
|
-
import { validatePhoneNumber } from
|
|
64
|
+
import { validatePhoneNumber } from "global-phone-validator";
|
|
28
65
|
|
|
29
66
|
// International format with country code
|
|
30
|
-
const result1 = validatePhoneNumber(
|
|
67
|
+
const result1 = validatePhoneNumber("+91 98765 43210");
|
|
31
68
|
console.log(result1);
|
|
32
69
|
// {
|
|
33
70
|
// isValid: true,
|
|
@@ -41,15 +78,27 @@ console.log(result1);
|
|
|
41
78
|
// }
|
|
42
79
|
|
|
43
80
|
// 0-prefixed format (India)
|
|
44
|
-
const result2 = validatePhoneNumber(
|
|
81
|
+
const result2 = validatePhoneNumber("09876543210");
|
|
45
82
|
console.log(result2.isValid); // true
|
|
46
83
|
|
|
47
84
|
// Plain digits with default country
|
|
48
|
-
const result3 = validatePhoneNumber(
|
|
85
|
+
const result3 = validatePhoneNumber("9876543210", "IN");
|
|
49
86
|
console.log(result3.isValid); // true
|
|
50
87
|
|
|
88
|
+
// Auto-detection from country code (no defaultCountry needed)
|
|
89
|
+
const result3a = validatePhoneNumber("+4917677274194");
|
|
90
|
+
console.log(result3a.isValid); // true - Auto-detects Germany from +49
|
|
91
|
+
console.log(result3a.country); // "DE" (Germany)
|
|
92
|
+
|
|
93
|
+
// Country matching validation (strict mode with defaultCountry)
|
|
94
|
+
const result3b = validatePhoneNumber("+4917677274194", "IN");
|
|
95
|
+
console.log(result3b.isValid); // false - Germany number doesn't match IN
|
|
96
|
+
|
|
97
|
+
const result3c = validatePhoneNumber("+4917677274194", "DE");
|
|
98
|
+
console.log(result3c.isValid); // true - Germany number matches DE
|
|
99
|
+
|
|
51
100
|
// US number
|
|
52
|
-
const result4 = validatePhoneNumber(
|
|
101
|
+
const result4 = validatePhoneNumber("+1 555 123 4567");
|
|
53
102
|
console.log(result4);
|
|
54
103
|
// {
|
|
55
104
|
// isValid: true,
|
|
@@ -65,28 +114,32 @@ console.log(result4);
|
|
|
65
114
|
|
|
66
115
|
```typescript
|
|
67
116
|
// Only accept mobile numbers
|
|
68
|
-
const result = validatePhoneNumber(
|
|
117
|
+
const result = validatePhoneNumber("9876543210", "IN", true);
|
|
69
118
|
console.log(result.isValid); // true (mobile number)
|
|
70
119
|
|
|
71
|
-
const result2 = validatePhoneNumber(
|
|
120
|
+
const result2 = validatePhoneNumber("0123456789", "IN", true);
|
|
72
121
|
console.log(result2.isValid); // false (landline number)
|
|
73
122
|
```
|
|
74
123
|
|
|
75
124
|
### Get Country Codes
|
|
76
125
|
|
|
77
126
|
```typescript
|
|
78
|
-
import {
|
|
127
|
+
import {
|
|
128
|
+
getAllCountryCodes,
|
|
129
|
+
getCountryDialCode,
|
|
130
|
+
getCountryCodeByDialCode,
|
|
131
|
+
} from "global-phone-validator";
|
|
79
132
|
|
|
80
133
|
// Get all country codes
|
|
81
134
|
const countries = getAllCountryCodes();
|
|
82
135
|
console.log(countries); // Array of all countries
|
|
83
136
|
|
|
84
137
|
// Get dial code for a country
|
|
85
|
-
const dialCode = getCountryDialCode(
|
|
138
|
+
const dialCode = getCountryDialCode("IN");
|
|
86
139
|
console.log(dialCode); // '91'
|
|
87
140
|
|
|
88
141
|
// Get country by dial code
|
|
89
|
-
const country = getCountryCodeByDialCode(
|
|
142
|
+
const country = getCountryCodeByDialCode("91");
|
|
90
143
|
console.log(country); // { name: 'India', dial_code: '+91', code: 'IN' }
|
|
91
144
|
```
|
|
92
145
|
|
|
@@ -97,8 +150,14 @@ console.log(country); // { name: 'India', dial_code: '+91', code: 'IN' }
|
|
|
97
150
|
Validates a phone number and returns detailed information.
|
|
98
151
|
|
|
99
152
|
**Parameters:**
|
|
153
|
+
|
|
100
154
|
- `input` (string): Phone number in various formats
|
|
101
|
-
- `defaultCountry` (string, optional): ISO country code (e.g., "IN", "US")
|
|
155
|
+
- `defaultCountry` (string, optional): ISO country code (e.g., "IN", "US").
|
|
156
|
+
- **When number has `+` prefix**:
|
|
157
|
+
- Country is **auto-detected** from the dial code (e.g., `+49` → Germany, `+91` → India)
|
|
158
|
+
- If `defaultCountry` is provided: Validates that detected country **matches** `defaultCountry` (strict mode)
|
|
159
|
+
- If `defaultCountry` is **not provided**: Validates based on the **detected country** from the dial code
|
|
160
|
+
- **When number doesn't have `+` prefix**: `defaultCountry` is **REQUIRED** - no default country is assumed
|
|
102
161
|
- `mobileOnly` (boolean, optional): If true, only accepts mobile numbers (currently only for India). Default: false
|
|
103
162
|
|
|
104
163
|
**Returns:** `PhoneValidationResult`
|
|
@@ -106,13 +165,13 @@ Validates a phone number and returns detailed information.
|
|
|
106
165
|
```typescript
|
|
107
166
|
interface PhoneValidationResult {
|
|
108
167
|
isValid: boolean;
|
|
109
|
-
countryCode?: string;
|
|
110
|
-
nationalNumber?: string;
|
|
111
|
-
e164?: string;
|
|
112
|
-
isMobile?: boolean;
|
|
113
|
-
isFixedLine?: boolean;
|
|
114
|
-
country?: string;
|
|
115
|
-
countryName?: string;
|
|
168
|
+
countryCode?: string; // e.g., '91'
|
|
169
|
+
nationalNumber?: string; // e.g., '9876543210'
|
|
170
|
+
e164?: string; // e.g., '+919876543210'
|
|
171
|
+
isMobile?: boolean; // true if mobile (India only)
|
|
172
|
+
isFixedLine?: boolean; // true if landline (India only)
|
|
173
|
+
country?: string; // ISO country code, e.g., 'IN'
|
|
174
|
+
countryName?: string; // Full country name, e.g., 'India'
|
|
116
175
|
}
|
|
117
176
|
```
|
|
118
177
|
|
|
@@ -124,9 +183,9 @@ Returns an array of all supported countries.
|
|
|
124
183
|
|
|
125
184
|
```typescript
|
|
126
185
|
interface CountryCode {
|
|
127
|
-
name: string;
|
|
128
|
-
dial_code: string;
|
|
129
|
-
code: string;
|
|
186
|
+
name: string; // e.g., 'India'
|
|
187
|
+
dial_code: string; // e.g., '+91'
|
|
188
|
+
code: string; // e.g., 'IN'
|
|
130
189
|
}
|
|
131
190
|
```
|
|
132
191
|
|
|
@@ -135,6 +194,7 @@ interface CountryCode {
|
|
|
135
194
|
Gets the dial code for a country.
|
|
136
195
|
|
|
137
196
|
**Parameters:**
|
|
197
|
+
|
|
138
198
|
- `countryCode` (string): ISO country code (e.g., "IN")
|
|
139
199
|
|
|
140
200
|
**Returns:** `string | null` - The dial code without the + sign (e.g., "91")
|
|
@@ -144,6 +204,7 @@ Gets the dial code for a country.
|
|
|
144
204
|
Gets country information by dial code.
|
|
145
205
|
|
|
146
206
|
**Parameters:**
|
|
207
|
+
|
|
147
208
|
- `dialCode` (string): Dial code with or without + (e.g., "91" or "+91")
|
|
148
209
|
|
|
149
210
|
**Returns:** `CountryCode | null`
|
|
@@ -153,65 +214,158 @@ Gets country information by dial code.
|
|
|
153
214
|
The package handles phone numbers in the following formats:
|
|
154
215
|
|
|
155
216
|
1. **International format**: `+91 98765 43210` or `+919876543210`
|
|
156
|
-
|
|
157
|
-
|
|
217
|
+
- Country is auto-detected from the dial code
|
|
218
|
+
- `defaultCountry` parameter is optional (used for strict matching)
|
|
219
|
+
2. **0-prefixed**: `09876543210`
|
|
220
|
+
- **Requires** `defaultCountry` parameter (e.g., `validatePhoneNumber("09876543210", "IN")`)
|
|
221
|
+
3. **Plain digits**: `9876543210`
|
|
222
|
+
- **Requires** `defaultCountry` parameter (e.g., `validatePhoneNumber("9876543210", "IN")`)
|
|
158
223
|
|
|
159
224
|
## Country-Specific Validation
|
|
160
225
|
|
|
161
|
-
The package includes validation rules for **50+ major countries** with specific length and format requirements
|
|
226
|
+
The package includes **comprehensive validation rules** for **50+ major countries** with specific length and format requirements. Each country has its own validation pattern ensuring accurate phone number validation.
|
|
162
227
|
|
|
163
228
|
### Countries with Specific Validation Rules
|
|
164
229
|
|
|
165
|
-
|
|
230
|
+
#### Americas
|
|
231
|
+
|
|
166
232
|
- **United States/Canada (1)**: 10 digits
|
|
233
|
+
- **Brazil (55)**: 10-11 digits
|
|
234
|
+
- **Mexico (52)**: 10 digits
|
|
235
|
+
- **Argentina (54)**: 10 digits
|
|
236
|
+
- **Chile (56)**: 9 digits
|
|
237
|
+
- **Colombia (57)**: 10 digits
|
|
238
|
+
- **Venezuela (58)**: 10 digits
|
|
239
|
+
- **Peru (51)**: 9 digits
|
|
240
|
+
|
|
241
|
+
#### Europe
|
|
242
|
+
|
|
167
243
|
- **United Kingdom (44)**: 10-11 digits
|
|
168
244
|
- **Germany (49)**: 10-11 digits
|
|
169
245
|
- **France (33)**: 9 digits
|
|
170
|
-
- **Australia (61)**: 9 digits
|
|
171
|
-
- **Brazil (55)**: 10-11 digits
|
|
172
|
-
- **China (86)**: 11 digits
|
|
173
|
-
- **Japan (81)**: 10-11 digits
|
|
174
|
-
- **South Korea (82)**: 9-10 digits
|
|
175
|
-
- **Russia (7)**: 10 digits
|
|
176
|
-
- **Spain (34)**: 9 digits
|
|
177
246
|
- **Italy (39)**: 9-10 digits
|
|
247
|
+
- **Spain (34)**: 9 digits
|
|
178
248
|
- **Netherlands (31)**: 9 digits
|
|
179
249
|
- **Sweden (46)**: 9 digits
|
|
180
250
|
- **Norway (47)**: 8 digits
|
|
181
251
|
- **Poland (48)**: 9 digits
|
|
182
|
-
- **
|
|
252
|
+
- **Russia (7)**: 10 digits
|
|
253
|
+
- **Switzerland (41)**: 9 digits
|
|
254
|
+
- **Belgium (32)**: 9 digits
|
|
255
|
+
- **Greece (30)**: 10 digits
|
|
256
|
+
- **Portugal (351)**: 9 digits
|
|
257
|
+
- **Ireland (353)**: 9 digits
|
|
258
|
+
- **Czech Republic (420)**: 9 digits
|
|
259
|
+
- **Ukraine (380)**: 9 digits
|
|
260
|
+
- **And more...**
|
|
261
|
+
|
|
262
|
+
#### Asia-Pacific
|
|
263
|
+
|
|
264
|
+
- **India (91)**: 10 digits (mobile: 6-9, landline: 0-5) - Mobile/landline detection
|
|
265
|
+
- **China (86)**: 11 digits
|
|
266
|
+
- **Japan (81)**: 10-11 digits
|
|
267
|
+
- **South Korea (82)**: 9-10 digits
|
|
268
|
+
- **Australia (61)**: 9 digits
|
|
269
|
+
- **Indonesia (62)**: 9-11 digits
|
|
270
|
+
- **Philippines (63)**: 10 digits
|
|
271
|
+
- **Thailand (66)**: 9 digits
|
|
272
|
+
- **Malaysia (60)**: 9-10 digits
|
|
273
|
+
- **Singapore (65)**: 8 digits
|
|
274
|
+
- **New Zealand (64)**: 8-10 digits
|
|
275
|
+
- **Vietnam (84)**: 9-10 digits
|
|
183
276
|
- **Pakistan (92)**: 10 digits
|
|
184
|
-
- **
|
|
277
|
+
- **Turkey (90)**: 10 digits
|
|
278
|
+
- **UAE (971)**: 9 digits
|
|
279
|
+
- **Israel (972)**: 9 digits
|
|
280
|
+
- **Hong Kong (852)**: 8 digits
|
|
281
|
+
- **Taiwan (886)**: 9 digits
|
|
282
|
+
- **And more...**
|
|
283
|
+
|
|
284
|
+
#### Africa & Middle East
|
|
285
|
+
|
|
286
|
+
- **South Africa (27)**: 9 digits
|
|
287
|
+
- **Nigeria (234)**: 10 digits
|
|
288
|
+
- **Kenya (254)**: 9 digits
|
|
289
|
+
- **Egypt (20)**: 8-10 digits
|
|
290
|
+
- **Morocco (212)**: 9 digits
|
|
291
|
+
- **Qatar (974)**: 8 digits
|
|
292
|
+
- **And more...**
|
|
185
293
|
|
|
186
294
|
### Other Countries
|
|
187
|
-
|
|
295
|
+
|
|
296
|
+
- **General validation**: 4-15 digits (ITU-T E.164 standard)
|
|
297
|
+
- All countries from CountryCodes.json are supported
|
|
298
|
+
- Falls back to general validation for countries without specific rules
|
|
188
299
|
|
|
189
300
|
## Examples
|
|
190
301
|
|
|
191
302
|
```typescript
|
|
192
|
-
import { validatePhoneNumber } from
|
|
303
|
+
import { validatePhoneNumber } from "global-phone-validator";
|
|
193
304
|
|
|
194
305
|
// Valid Indian mobile number
|
|
195
|
-
validatePhoneNumber(
|
|
306
|
+
validatePhoneNumber("+91 98765 43210");
|
|
196
307
|
// { isValid: true, isMobile: true, e164: '+919876543210', ... }
|
|
197
308
|
|
|
198
309
|
// Valid Indian landline
|
|
199
|
-
validatePhoneNumber(
|
|
310
|
+
validatePhoneNumber("0123456789", "IN");
|
|
200
311
|
// { isValid: true, isFixedLine: true, ... }
|
|
201
312
|
|
|
202
313
|
// Invalid number
|
|
203
|
-
validatePhoneNumber(
|
|
314
|
+
validatePhoneNumber("12345");
|
|
204
315
|
// { isValid: false }
|
|
205
316
|
|
|
206
317
|
// US number
|
|
207
|
-
validatePhoneNumber(
|
|
318
|
+
validatePhoneNumber("+1 555 123 4567");
|
|
208
319
|
// { isValid: true, country: 'US', e164: '+15551234567', ... }
|
|
209
320
|
|
|
210
321
|
// UK number
|
|
211
|
-
validatePhoneNumber(
|
|
322
|
+
validatePhoneNumber("+44 20 7946 0958");
|
|
212
323
|
// { isValid: true, country: 'GB', e164: '+442079460958', ... }
|
|
324
|
+
|
|
325
|
+
// Germany number (mobile)
|
|
326
|
+
validatePhoneNumber("+49 17677274194");
|
|
327
|
+
// { isValid: true, country: 'DE', e164: '+4917677274194', ... }
|
|
328
|
+
|
|
329
|
+
// Germany number (landline)
|
|
330
|
+
validatePhoneNumber("+49 30 12345678");
|
|
331
|
+
// { isValid: true, country: 'DE', e164: '+493012345678', ... }
|
|
332
|
+
|
|
333
|
+
// France number
|
|
334
|
+
validatePhoneNumber("+33 1 23 45 67 89");
|
|
335
|
+
// { isValid: true, country: 'FR', e164: '+33123456789', ... }
|
|
336
|
+
|
|
337
|
+
// Australia number
|
|
338
|
+
validatePhoneNumber("+61 2 1234 5678");
|
|
339
|
+
// { isValid: true, country: 'AU', e164: '+61212345678', ... }
|
|
340
|
+
|
|
341
|
+
// Brazil number
|
|
342
|
+
validatePhoneNumber("+55 11 98765 4321");
|
|
343
|
+
// { isValid: true, country: 'BR', e164: '+5511987654321', ... }
|
|
344
|
+
|
|
345
|
+
// China number
|
|
346
|
+
validatePhoneNumber("+86 138 0013 8000");
|
|
347
|
+
// { isValid: true, country: 'CN', e164: '+8613800138000', ... }
|
|
348
|
+
|
|
349
|
+
// Japan number
|
|
350
|
+
validatePhoneNumber("+81 3 1234 5678");
|
|
351
|
+
// { isValid: true, country: 'JP', e164: '+81312345678', ... }
|
|
352
|
+
|
|
353
|
+
// Germany number with different spacing (all formats work)
|
|
354
|
+
validatePhoneNumber("+49 17677274194"); // With space after country code
|
|
355
|
+
validatePhoneNumber("+49 176 77274194"); // With spaces in number
|
|
356
|
+
validatePhoneNumber("+4917677274194"); // No spaces
|
|
357
|
+
// All produce: { isValid: true, country: 'DE', nationalNumber: '17677274194', e164: '+4917677274194', ... }
|
|
213
358
|
```
|
|
214
359
|
|
|
360
|
+
## Why Use This Package?
|
|
361
|
+
|
|
362
|
+
- **Accurate**: Country-specific validation rules ensure phone numbers are validated correctly
|
|
363
|
+
- **Comprehensive**: Supports all countries with specific rules for 50+ major countries
|
|
364
|
+
- **Lightweight**: Zero dependencies, small package size
|
|
365
|
+
- **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
366
|
+
- **Flexible**: Handles multiple input formats (international, 0-prefixed, plain digits)
|
|
367
|
+
- **Standardized**: Returns E.164 format for consistent phone number representation
|
|
368
|
+
|
|
215
369
|
## Development
|
|
216
370
|
|
|
217
371
|
```bash
|
|
@@ -225,11 +379,29 @@ npm run build
|
|
|
225
379
|
npm test
|
|
226
380
|
```
|
|
227
381
|
|
|
382
|
+
## Contributing
|
|
383
|
+
|
|
384
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
385
|
+
|
|
386
|
+
### Adding Country Validation Rules
|
|
387
|
+
|
|
388
|
+
If you'd like to add or improve validation rules for specific countries, please:
|
|
389
|
+
|
|
390
|
+
1. Fork the repository
|
|
391
|
+
2. Add the validation rule to the `validationRules` object in `src/index.ts`
|
|
392
|
+
3. Update the README with the country information
|
|
393
|
+
4. Submit a Pull Request
|
|
394
|
+
|
|
228
395
|
## License
|
|
229
396
|
|
|
230
397
|
MIT
|
|
231
398
|
|
|
232
|
-
##
|
|
399
|
+
## Links
|
|
233
400
|
|
|
234
|
-
|
|
401
|
+
- **NPM Package**: [global-phone-validator](https://www.npmjs.com/package/global-phone-validator)
|
|
402
|
+
- **GitHub Repository**: [AVantala/global-phone-validator](https://github.com/AVantala/global-phone-validator)
|
|
403
|
+
- **Issues**: [Report a bug or request a feature](https://github.com/AVantala/global-phone-validator/issues)
|
|
404
|
+
|
|
405
|
+
## License
|
|
235
406
|
|
|
407
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ import { PhoneValidationResult } from "./types";
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function validatePhoneNumber(input: string, defaultCountry?: string, mobileOnly?: boolean): PhoneValidationResult;
|
|
17
17
|
export type { PhoneValidationResult, CountryCode } from "./types";
|
|
18
|
-
export { getAllCountryCodes, getCountryDialCode, getCountryCodeByDialCode } from "./utils";
|
|
18
|
+
export { getAllCountryCodes, getCountryDialCode, getCountryCodeByDialCode, } from "./utils";
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAe,MAAM,SAAS,CAAC;AAW7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAe,MAAM,SAAS,CAAC;AAW7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,cAAc,CAAC,EAAE,MAAM,EACvB,UAAU,GAAE,OAAe,GAC1B,qBAAqB,CAiMvB;AAGD,YAAY,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ const COUNTRY_CODES = CountryCodes_json_1.default;
|
|
|
22
22
|
* validatePhoneNumber("9876543210", "IN") // India plain digits
|
|
23
23
|
* validatePhoneNumber("+1 555 123 4567") // US number
|
|
24
24
|
*/
|
|
25
|
-
function validatePhoneNumber(input, defaultCountry
|
|
25
|
+
function validatePhoneNumber(input, defaultCountry, mobileOnly = false) {
|
|
26
26
|
if (!input || typeof input !== "string") {
|
|
27
27
|
return { isValid: false };
|
|
28
28
|
}
|
|
@@ -40,6 +40,13 @@ function validatePhoneNumber(input, defaultCountry = "IN", mobileOnly = false) {
|
|
|
40
40
|
detectedCountry = detection.country;
|
|
41
41
|
countryCode = detection.dialCode;
|
|
42
42
|
nationalNumber = detection.nationalNumber;
|
|
43
|
+
// If defaultCountry is provided, validate that detected country matches
|
|
44
|
+
if (defaultCountry) {
|
|
45
|
+
const expectedDialCode = (0, utils_1.getCountryDialCode)(defaultCountry);
|
|
46
|
+
if (expectedDialCode && countryCode !== expectedDialCode) {
|
|
47
|
+
return { isValid: false };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
else {
|
|
45
52
|
return { isValid: false };
|
|
@@ -47,23 +54,31 @@ function validatePhoneNumber(input, defaultCountry = "IN", mobileOnly = false) {
|
|
|
47
54
|
}
|
|
48
55
|
// Handle 0-prefixed numbers (common in many countries)
|
|
49
56
|
else if (cleaned.startsWith("0")) {
|
|
57
|
+
if (!defaultCountry) {
|
|
58
|
+
return { isValid: false }; // Require defaultCountry for 0-prefixed numbers
|
|
59
|
+
}
|
|
50
60
|
const defaultDialCode = (0, utils_1.getCountryDialCode)(defaultCountry);
|
|
51
61
|
if (!defaultDialCode) {
|
|
52
62
|
return { isValid: false };
|
|
53
63
|
}
|
|
54
64
|
countryCode = defaultDialCode;
|
|
55
65
|
nationalNumber = cleaned.substring(1);
|
|
56
|
-
detectedCountry =
|
|
66
|
+
detectedCountry =
|
|
67
|
+
COUNTRY_CODES.find((c) => c.code.toUpperCase() === defaultCountry.toUpperCase()) || null;
|
|
57
68
|
}
|
|
58
|
-
// Handle plain digits (
|
|
69
|
+
// Handle plain digits (require defaultCountry)
|
|
59
70
|
else {
|
|
71
|
+
if (!defaultCountry) {
|
|
72
|
+
return { isValid: false }; // Require defaultCountry for plain digits
|
|
73
|
+
}
|
|
60
74
|
const defaultDialCode = (0, utils_1.getCountryDialCode)(defaultCountry);
|
|
61
75
|
if (!defaultDialCode) {
|
|
62
76
|
return { isValid: false };
|
|
63
77
|
}
|
|
64
78
|
countryCode = defaultDialCode;
|
|
65
79
|
nationalNumber = cleaned;
|
|
66
|
-
detectedCountry =
|
|
80
|
+
detectedCountry =
|
|
81
|
+
COUNTRY_CODES.find((c) => c.code.toUpperCase() === defaultCountry.toUpperCase()) || null;
|
|
67
82
|
}
|
|
68
83
|
// Validate national number length (general rule: 4-15 digits)
|
|
69
84
|
if (nationalNumber.length < 4 || nationalNumber.length > 15) {
|
|
@@ -138,7 +153,8 @@ function validatePhoneNumber(input, defaultCountry = "IN", mobileOnly = false) {
|
|
|
138
153
|
const rule = validationRules[countryCode];
|
|
139
154
|
if (rule) {
|
|
140
155
|
// Use country-specific validation
|
|
141
|
-
if (nationalNumber.length < rule.minLength ||
|
|
156
|
+
if (nationalNumber.length < rule.minLength ||
|
|
157
|
+
nationalNumber.length > rule.maxLength) {
|
|
142
158
|
return { isValid: false };
|
|
143
159
|
}
|
|
144
160
|
if (!rule.pattern.test(nationalNumber)) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAyBA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAyBA,kDAqMC;AA7ND,mCAKiB;AACjB,4EAA+C;AAE/C,MAAM,aAAa,GAAG,2BAA6B,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AACH,SAAgB,mBAAmB,CACjC,KAAa,EACb,cAAuB,EACvB,aAAsB,KAAK;IAE3B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,MAAM,OAAO,GAAG,IAAA,wBAAgB,EAAC,KAAK,CAAC,CAA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AAC;QACrC,iDAAiD;QACjD,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,QAAQ,GAAG,IAAI,CAAC;YAChB,WAAW,GAAG,KAAK,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,4CAA4C;YAC5C,QAAQ,GAAG,KAAK,CAAC;YACjB,WAAW,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,IAAI,UAAU,IAAI,WAAW,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,WAAW;QACX,cAAc;QACd,IAAI,EAAE,IAAI,WAAW,GAAG,cAAc,EAAE;QACxC,QAAQ;QACR,WAAW;QACX,OAAO,EAAE,eAAe,EAAE,IAAI;QAC9B,WAAW,EAAE,eAAe,EAAE,IAAI;KACnC,CAAC;AACJ,CAAC;AAID,iCAIiB;AAHf,2GAAA,kBAAkB,OAAA;AAClB,2GAAA,kBAAkB,OAAA;AAClB,iHAAA,wBAAwB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "global-phone-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A reusable Node.js + TypeScript package for validating phone numbers worldwide. Supports any country using CountryCodes JSON, handles international formats (+CC), 0-prefixed, and plain digits. Includes mobile/landline detection for India and returns standardized E.164 format.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|