ngx-dial-input 2.0.0 → 2.0.2
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/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
3
|
-
"version": "
|
|
2
|
+
"name": "ngx-dial-input",
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@angular/common": "15.
|
|
6
|
-
"@angular/core": "15.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"tslib": "^2.3.0"
|
|
10
|
-
},
|
|
11
|
-
"sideEffects": false
|
|
5
|
+
"@angular/common": "15.2.10",
|
|
6
|
+
"@angular/core": "15.2.10",
|
|
7
|
+
"@angular/forms": "^15.1.1"
|
|
8
|
+
}
|
|
12
9
|
}
|
|
@@ -55,14 +55,14 @@ import {
|
|
|
55
55
|
<!-- Phone Input (80%) -->
|
|
56
56
|
<input
|
|
57
57
|
type="tel"
|
|
58
|
-
pattern="[0-9]*"
|
|
58
|
+
pattern="[0-9\\s\\-]*"
|
|
59
59
|
inputmode="numeric"
|
|
60
60
|
class="phone-input"
|
|
61
61
|
[placeholder]="placeholder"
|
|
62
62
|
[(ngModel)]="phoneNumber"
|
|
63
63
|
[ngClass]="{ 'error-border': isInvalid }"
|
|
64
64
|
(input)="onPhoneInput()"
|
|
65
|
-
(keypress)="
|
|
65
|
+
(keypress)="allowPhoneCharacters($event)"
|
|
66
66
|
/>
|
|
67
67
|
</div>
|
|
68
68
|
|
|
@@ -257,13 +257,15 @@ export class PhoneInputComponent implements ControlValueAccessor {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
onSearchChange() {
|
|
261
261
|
const term = this.searchTerm.toLowerCase();
|
|
262
262
|
this.countriesList = countries.filter(c =>
|
|
263
|
-
c.name.toLowerCase().includes(term)
|
|
263
|
+
c.name.toLowerCase().includes(term) ||
|
|
264
|
+
(c.native?.toLowerCase().includes(term))
|
|
264
265
|
);
|
|
265
266
|
}
|
|
266
267
|
|
|
268
|
+
|
|
267
269
|
selectCountry(country: any) {
|
|
268
270
|
this.selectedCountry = country;
|
|
269
271
|
this.searchTerm = '';
|
|
@@ -277,23 +279,28 @@ export class PhoneInputComponent implements ControlValueAccessor {
|
|
|
277
279
|
}
|
|
278
280
|
|
|
279
281
|
private emitPhoneChange() {
|
|
280
|
-
const
|
|
281
|
-
const
|
|
282
|
+
const raw = this.phoneNumber || '';
|
|
283
|
+
const digitsOnly = raw.replace(/\D/g, '');
|
|
284
|
+
const hyphenCount = (raw.match(/-/g) || []).length;
|
|
285
|
+
const spaceCount = (raw.match(/ /g) || []).length;
|
|
282
286
|
|
|
283
|
-
const
|
|
287
|
+
const totalChars = this.phoneNumber.length;
|
|
288
|
+
const maxAllowedLength = this.selectedCountry?.phoneLength + hyphenCount + spaceCount;
|
|
284
289
|
|
|
285
|
-
if (
|
|
286
|
-
this.isInvalid =
|
|
287
|
-
} else {
|
|
288
|
-
// fallback validation
|
|
289
|
-
this.isInvalid = length < 7 || length > 12;
|
|
290
|
+
if (digitsOnly.length !== this.selectedCountry?.phoneLength) {
|
|
291
|
+
this.isInvalid = true;
|
|
290
292
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
+
else if (totalChars > maxAllowedLength) {
|
|
294
|
+
this.isInvalid = true;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
this.isInvalid = false;
|
|
298
|
+
}
|
|
299
|
+
const fullPhone = this.selectedCountry.dialCode + raw;
|
|
293
300
|
|
|
294
301
|
const structuredValue = {
|
|
295
302
|
e164Number: fullPhone,
|
|
296
|
-
nationalNumber:
|
|
303
|
+
nationalNumber: raw,
|
|
297
304
|
dialCode: this.selectedCountry.dialCode,
|
|
298
305
|
countryCode: this.selectedCountry.iso2,
|
|
299
306
|
isValid: !this.isInvalid,
|
|
@@ -326,13 +333,16 @@ export class PhoneInputComponent implements ControlValueAccessor {
|
|
|
326
333
|
registerOnTouched(fn: any): void {
|
|
327
334
|
this.onTouched = fn;
|
|
328
335
|
}
|
|
329
|
-
|
|
330
|
-
|
|
336
|
+
allowPhoneCharacters(event: KeyboardEvent) {
|
|
337
|
+
const allowedChars = [' ', '-'];
|
|
338
|
+
const charCode = event.charCode;
|
|
339
|
+
|
|
340
|
+
// Allow digits 0–9
|
|
341
|
+
if (charCode >= 48 && charCode <= 57) return;
|
|
342
|
+
|
|
343
|
+
// Allow hyphen and space
|
|
344
|
+
if (allowedChars.includes(event.key)) return;
|
|
331
345
|
|
|
332
|
-
// Allow only digits (0–9)
|
|
333
|
-
if (charCode < 48 || charCode > 57) {
|
|
334
346
|
event.preventDefault();
|
|
335
347
|
}
|
|
336
348
|
}
|
|
337
|
-
|
|
338
|
-
}
|
|
Binary file
|