Skip to content

Commit c7f9eed

Browse files
committed
BREAKING: make isValidNumberPrecise respect validationNumberType
1 parent 5623901 commit c7f9eed

19 files changed

+869
-853
lines changed

build/js/intlTelInput.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ declare module "intl-tel-input" {
313313
getExtension(number: string, iso2: string | undefined): string;
314314
getNumberType: (number: string, iso2: string | undefined) => number;
315315
getValidationError(number: string, iso2: string | undefined): number;
316-
isPossibleNumber(number: string, iso2: string | undefined, numberType?: string): boolean;
317-
isValidNumber: (number: string, iso2: string | undefined) => boolean;
316+
isPossibleNumber(number: string, iso2: string | undefined, numberType?: string | null): boolean;
317+
isValidNumber: (number: string, iso2: string | undefined, numberType?: string | null) => boolean;
318318
numberFormat: {
319319
NATIONAL: number;
320320
INTERNATIONAL: number;

build/js/intlTelInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,7 @@ var factoryOutput = (() => {
30523052
return this._utilsIsValidNumber(val);
30533053
}
30543054
_utilsIsValidNumber(val) {
3055-
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
3055+
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
30563056
}
30573057
//* Update the selected country, and update the input val accordingly.
30583058
setCountry(iso2) {

build/js/intlTelInput.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/js/intlTelInputWithUtils.js

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

build/js/intlTelInputWithUtils.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/js/utils.js

Lines changed: 30 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/build/IntlTelInput.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3047,7 +3047,7 @@ var Iti = class {
30473047
return this._utilsIsValidNumber(val);
30483048
}
30493049
_utilsIsValidNumber(val) {
3050-
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
3050+
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
30513051
}
30523052
//* Update the selected country, and update the input val accordingly.
30533053
setCountry(iso2) {

react/build/IntlTelInput.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ declare module "intl-tel-input" {
313313
getExtension(number: string, iso2: string | undefined): string;
314314
getNumberType: (number: string, iso2: string | undefined) => number;
315315
getValidationError(number: string, iso2: string | undefined): number;
316-
isPossibleNumber(number: string, iso2: string | undefined, numberType?: string): boolean;
317-
isValidNumber: (number: string, iso2: string | undefined) => boolean;
316+
isPossibleNumber(number: string, iso2: string | undefined, numberType?: string | null): boolean;
317+
isValidNumber: (number: string, iso2: string | undefined, numberType?: string | null) => boolean;
318318
numberFormat: {
319319
NATIONAL: number;
320320
INTERNATIONAL: number;

react/build/IntlTelInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3011,7 +3011,7 @@ var Iti = class {
30113011
return this._utilsIsValidNumber(val);
30123012
}
30133013
_utilsIsValidNumber(val) {
3014-
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
3014+
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
30153015
}
30163016
//* Update the selected country, and update the input val accordingly.
30173017
setCountry(iso2) {

react/build/IntlTelInputWithUtils.cjs

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

react/build/IntlTelInputWithUtils.js

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

react/demo/set-number/set-number-bundle.js

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

react/demo/simple/simple-bundle.js

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

react/demo/toggle-disabled/toggle-disabled-bundle.js

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

react/demo/validation/validation-bundle.js

Lines changed: 89 additions & 87 deletions
Large diffs are not rendered by default.

src/js/intl-tel-input.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type ItiUtils = {
3131
getExtension(number: string, iso2: string | undefined): string;
3232
getNumberType: (number: string, iso2: string | undefined) => number;
3333
getValidationError(number: string, iso2: string | undefined): number;
34-
isPossibleNumber(number: string, iso2: string | undefined, numberType?: string): boolean;
35-
isValidNumber: (number: string, iso2: string | undefined) => boolean;
34+
isPossibleNumber(number: string, iso2: string | undefined, numberType?: string | null): boolean;
35+
isValidNumber: (number: string, iso2: string | undefined, numberType?: string | null) => boolean;
3636
numberFormat: { NATIONAL: number, INTERNATIONAL: number, E164: number, RFC3966: number };
3737
numberType: object;
3838
};
@@ -2086,7 +2086,7 @@ export class Iti {
20862086

20872087
private _utilsIsValidNumber(val: string): boolean | null {
20882088
return intlTelInput.utils
2089-
? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2)
2089+
? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType)
20902090
: null;
20912091
}
20922092

src/js/utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,23 @@ const getValidationError = (number, countryCode) => {
131131
};
132132

133133
//* Check if given number is valid.
134-
const isValidNumber = (number, countryCode) => {
134+
const isValidNumber = (number, countryCode, numberTypeName) => {
135135
try {
136136
const phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
137137
const numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
138-
return phoneUtil.isValidNumber(numberObj);
138+
const isValidNumber = phoneUtil.isValidNumber(numberObj);
139+
if (numberTypeName) {
140+
return isValidNumber && phoneUtil.getNumberType(numberObj) === numberType[numberTypeName];
141+
}
142+
return isValidNumber;
139143
} catch {
140144
return false;
141145
}
142146
};
143147

144148
//* For internal use only - see isPossibleNumber.
145149
const isPossibleNumberForType = (phoneUtil, numberObj, numberTypeName) => {
150+
//* Can't use phoneUtil.isPossibleNumberForType directly as it accepts IS_POSSIBLE_LOCAL_ONLY numbers e.g. local numbers that are much shorter.
146151
const resultForType = phoneUtil.isPossibleNumberForTypeWithReason(numberObj, numberType[numberTypeName]);
147152
const isPossibleForType = resultForType === i18n.phonenumbers.PhoneNumberUtil.ValidationResult.IS_POSSIBLE;
148153
return isPossibleForType;

vue/build/IntlTelInput.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,7 @@ class G {
24342434
return this._utilsIsValidNumber(t);
24352435
}
24362436
_utilsIsValidNumber(t) {
2437-
return l.utils ? l.utils.isValidNumber(t, this.selectedCountryData.iso2) : null;
2437+
return l.utils ? l.utils.isValidNumber(t, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
24382438
}
24392439
//* Update the selected country, and update the input val accordingly.
24402440
setCountry(t) {

0 commit comments

Comments
 (0)