intl-tel-input 23.8.0 → 23.8.1
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 +43 -43
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.d.ts +2 -0
- package/build/js/intlTelInput.js +23 -6
- package/build/js/intlTelInput.min.js +2 -2
- package/build/js/intlTelInputWithUtils.js +23 -6
- package/build/js/intlTelInputWithUtils.min.js +2 -2
- package/package.json +1 -1
- package/react/README.md +21 -21
- package/react/build/IntlTelInput.cjs +22 -5
- package/react/build/IntlTelInput.d.ts +2 -0
- package/react/build/IntlTelInput.js +22 -5
- package/react/build/IntlTelInputWithUtils.cjs +22 -5
- package/react/build/IntlTelInputWithUtils.js +22 -5
package/package.json
CHANGED
package/react/README.md
CHANGED
|
@@ -27,49 +27,49 @@ import "intl-tel-input/styles";
|
|
|
27
27
|
/>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/ValidationApp.tsx) for a more fleshed
|
|
30
|
+
See the [Validation demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/ValidationApp.tsx) for a more fleshed-out example of how to handle validation.
|
|
31
31
|
|
|
32
|
-
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"` instead, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@23.8.
|
|
32
|
+
A note on the utils script (~260KB): if you're lazy loading the IntlTelInput chunk (and so less worried about filesize) then you can just import IntlTelInput from `"intl-tel-input/reactWithUtils"` instead, to include the utils script. Alternatively, if you use the main `"intl-tel-input/react"` import, then you should couple this with the `utilsScript` initialisation option - you will need to host the [utils.js](https://github.com/jackocnr/intl-tel-input/blob/master/build/js/utils.js) file, and then set the `utilsScript` option to that URL, or alternatively just point it to a CDN hosted version e.g. `"https://cdn.jsdelivr.net/npm/intl-tel-input@23.8.1/build/js/utils.js"`.
|
|
33
33
|
|
|
34
34
|
## Props
|
|
35
35
|
Here's a list of all of the current props you can pass to the IntlTelInput react component.
|
|
36
36
|
|
|
37
|
+
**disabled**
|
|
38
|
+
Type: `Boolean`, Default: `false`
|
|
39
|
+
Sets the disabled attribute of both the telephone input and selected country button. _Note: we recommend using this instead of `inputProps.disabled`._
|
|
40
|
+
|
|
37
41
|
**initialValue**
|
|
38
42
|
Type: `String`
|
|
39
43
|
The initial value to put in the input. This will get auto-formatted on init (according to `formatOnDisplay` initialisation option). IntlTelInput is an uncontrolled input, and so will ignore any changes to this value.
|
|
40
44
|
|
|
41
|
-
**
|
|
42
|
-
Type: `
|
|
43
|
-
|
|
45
|
+
**initOptions**
|
|
46
|
+
Type: `Object`
|
|
47
|
+
An object containing all of the [initialisation options](https://github.com/jackocnr/intl-tel-input?tab=readme-ov-file#initialisation-options) to pass to the plugin. You can use these exactly the same as when using the plugin with pure JavaScript.
|
|
48
|
+
|
|
49
|
+
**inputProps**
|
|
50
|
+
Type: `Object`
|
|
51
|
+
The props to pass to the input element e.g. `className`, `placeholder`, `required`, `onBlur` etc. _Note: we recommend using the separate `disabled` prop instead of `inputProps.disabled`._
|
|
44
52
|
|
|
45
53
|
**onChangeCountry**
|
|
46
54
|
Type: `Function`
|
|
47
55
|
A handler to be called when the selected country changes. It will be passed the new country iso2 code e.g. "gb" for UK.
|
|
48
56
|
|
|
49
|
-
**onChangeValidity**
|
|
50
|
-
Type: `Function`
|
|
51
|
-
A handler to be called when the number validity changes e.g. to true/false. It will be passed the new isValid boolean.
|
|
52
|
-
|
|
53
57
|
**onChangeErrorCode**
|
|
54
58
|
Type: `Function`
|
|
55
59
|
A handler to be called when the number validation error changes. It will be passed the new error code (or `null`).
|
|
56
60
|
|
|
61
|
+
**onChangeNumber**
|
|
62
|
+
Type: `Function`
|
|
63
|
+
A handler to be called when the number changes. It will be passed the new number.
|
|
64
|
+
|
|
65
|
+
**onChangeValidity**
|
|
66
|
+
Type: `Function`
|
|
67
|
+
A handler to be called when the number validity changes e.g. to true/false. It will be passed the new isValid boolean.
|
|
68
|
+
|
|
57
69
|
**usePreciseValidation**
|
|
58
70
|
Type: `Boolean`, Default: `false`
|
|
59
71
|
By default we use `isValidNumber` for validation, but if you'd rather use `isValidNumberPrecise` you can set this to `true`.
|
|
60
72
|
|
|
61
|
-
**initOptions**
|
|
62
|
-
Type: `Object`
|
|
63
|
-
An object containing all of the [initialisation options](https://github.com/jackocnr/intl-tel-input?tab=readme-ov-file#initialisation-options) to pass to the plugin. You can use these exactly the same as when using the plugin with pure JavaScript.
|
|
64
|
-
|
|
65
|
-
**inputProps**
|
|
66
|
-
Type: `Object`
|
|
67
|
-
The props to pass to the input element e.g. `className`, `placeholder`, `required`, `onBlur` etc. _Note: we recommend using the separate `disabled` prop instead of `inputProps.disabled`._
|
|
68
|
-
|
|
69
|
-
**disabled**
|
|
70
|
-
Type: `Boolean`, Default: `false`
|
|
71
|
-
Sets the disabled attribute of both the telephone input and selected country button. _Note: we recommend using this instead of `inputProps.disabled`._
|
|
72
|
-
|
|
73
73
|
## Accessing Instance Methods
|
|
74
74
|
|
|
75
75
|
You can access all of the plugin's [instance methods](https://github.com/jackocnr/intl-tel-input/blob/master/README.md#instance-methods) (`setNumber`, `setCountry`, `setPlaceholderNumberType` etc) by passing a ref into the IntlTelInput component (using the `ref` prop), and then calling `ref.current.getInstance()` e.g. `ref.current.getInstance().setNumber(...);`. See the [Set Number demo](https://github.com/jackocnr/intl-tel-input/blob/master/react/demo/SetNumberApp.tsx) for a full example. You can also access the input DOM element in a similar way: `ref.current.getInput()`.
|
|
@@ -1992,6 +1992,9 @@ var Iti = class {
|
|
|
1992
1992
|
_initTelInputListeners() {
|
|
1993
1993
|
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
1994
1994
|
let userOverrideFormatting = false;
|
|
1995
|
+
if (/\p{L}/u.test(this.telInput.value)) {
|
|
1996
|
+
userOverrideFormatting = true;
|
|
1997
|
+
}
|
|
1995
1998
|
const openDropdownWithPlus = () => {
|
|
1996
1999
|
this._openDropdown();
|
|
1997
2000
|
this.searchInput.value = "+";
|
|
@@ -2732,17 +2735,31 @@ var Iti = class {
|
|
|
2732
2735
|
//* Validate the input val
|
|
2733
2736
|
isValidNumber() {
|
|
2734
2737
|
const val = this._getFullNumber();
|
|
2735
|
-
|
|
2736
|
-
|
|
2738
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2739
|
+
if (alphaCharPosition > -1) {
|
|
2740
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2741
|
+
const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
|
|
2742
|
+
const isValid = this._utilsIsPossibleNumber(val);
|
|
2743
|
+
return beforeAlphaIsValid && isValid;
|
|
2737
2744
|
}
|
|
2745
|
+
return this._utilsIsPossibleNumber(val);
|
|
2746
|
+
}
|
|
2747
|
+
_utilsIsPossibleNumber(val) {
|
|
2738
2748
|
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
|
|
2739
2749
|
}
|
|
2740
2750
|
//* Validate the input val (precise)
|
|
2741
2751
|
isValidNumberPrecise() {
|
|
2742
2752
|
const val = this._getFullNumber();
|
|
2743
|
-
|
|
2744
|
-
|
|
2753
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2754
|
+
if (alphaCharPosition > -1) {
|
|
2755
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2756
|
+
const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
|
|
2757
|
+
const isValid = this._utilsIsValidNumber(val);
|
|
2758
|
+
return beforeAlphaIsValid && isValid;
|
|
2745
2759
|
}
|
|
2760
|
+
return this._utilsIsValidNumber(val);
|
|
2761
|
+
}
|
|
2762
|
+
_utilsIsValidNumber(val) {
|
|
2746
2763
|
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
|
|
2747
2764
|
}
|
|
2748
2765
|
//* Update the selected country, and update the input val accordingly.
|
|
@@ -2821,7 +2838,7 @@ var intlTelInput = Object.assign(
|
|
|
2821
2838
|
//* A map from instance ID to instance object.
|
|
2822
2839
|
instances: {},
|
|
2823
2840
|
loadUtils,
|
|
2824
|
-
version: "23.8.
|
|
2841
|
+
version: "23.8.1"
|
|
2825
2842
|
}
|
|
2826
2843
|
);
|
|
2827
2844
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -969,7 +969,9 @@ declare module "intl-tel-input" {
|
|
|
969
969
|
getSelectedCountryData(): SelectedCountryData;
|
|
970
970
|
getValidationError(): number;
|
|
971
971
|
isValidNumber(): boolean | null;
|
|
972
|
+
private _utilsIsPossibleNumber;
|
|
972
973
|
isValidNumberPrecise(): boolean | null;
|
|
974
|
+
private _utilsIsValidNumber;
|
|
973
975
|
setCountry(iso2: string): void;
|
|
974
976
|
setNumber(number: string): void;
|
|
975
977
|
setPlaceholderNumberType(type: NumberType): void;
|
|
@@ -1956,6 +1956,9 @@ var Iti = class {
|
|
|
1956
1956
|
_initTelInputListeners() {
|
|
1957
1957
|
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
1958
1958
|
let userOverrideFormatting = false;
|
|
1959
|
+
if (/\p{L}/u.test(this.telInput.value)) {
|
|
1960
|
+
userOverrideFormatting = true;
|
|
1961
|
+
}
|
|
1959
1962
|
const openDropdownWithPlus = () => {
|
|
1960
1963
|
this._openDropdown();
|
|
1961
1964
|
this.searchInput.value = "+";
|
|
@@ -2696,17 +2699,31 @@ var Iti = class {
|
|
|
2696
2699
|
//* Validate the input val
|
|
2697
2700
|
isValidNumber() {
|
|
2698
2701
|
const val = this._getFullNumber();
|
|
2699
|
-
|
|
2700
|
-
|
|
2702
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2703
|
+
if (alphaCharPosition > -1) {
|
|
2704
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2705
|
+
const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
|
|
2706
|
+
const isValid = this._utilsIsPossibleNumber(val);
|
|
2707
|
+
return beforeAlphaIsValid && isValid;
|
|
2701
2708
|
}
|
|
2709
|
+
return this._utilsIsPossibleNumber(val);
|
|
2710
|
+
}
|
|
2711
|
+
_utilsIsPossibleNumber(val) {
|
|
2702
2712
|
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
|
|
2703
2713
|
}
|
|
2704
2714
|
//* Validate the input val (precise)
|
|
2705
2715
|
isValidNumberPrecise() {
|
|
2706
2716
|
const val = this._getFullNumber();
|
|
2707
|
-
|
|
2708
|
-
|
|
2717
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2718
|
+
if (alphaCharPosition > -1) {
|
|
2719
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2720
|
+
const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
|
|
2721
|
+
const isValid = this._utilsIsValidNumber(val);
|
|
2722
|
+
return beforeAlphaIsValid && isValid;
|
|
2709
2723
|
}
|
|
2724
|
+
return this._utilsIsValidNumber(val);
|
|
2725
|
+
}
|
|
2726
|
+
_utilsIsValidNumber(val) {
|
|
2710
2727
|
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
|
|
2711
2728
|
}
|
|
2712
2729
|
//* Update the selected country, and update the input val accordingly.
|
|
@@ -2785,7 +2802,7 @@ var intlTelInput = Object.assign(
|
|
|
2785
2802
|
//* A map from instance ID to instance object.
|
|
2786
2803
|
instances: {},
|
|
2787
2804
|
loadUtils,
|
|
2788
|
-
version: "23.8.
|
|
2805
|
+
version: "23.8.1"
|
|
2789
2806
|
}
|
|
2790
2807
|
);
|
|
2791
2808
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -1992,6 +1992,9 @@ var Iti = class {
|
|
|
1992
1992
|
_initTelInputListeners() {
|
|
1993
1993
|
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
1994
1994
|
let userOverrideFormatting = false;
|
|
1995
|
+
if (/\p{L}/u.test(this.telInput.value)) {
|
|
1996
|
+
userOverrideFormatting = true;
|
|
1997
|
+
}
|
|
1995
1998
|
const openDropdownWithPlus = () => {
|
|
1996
1999
|
this._openDropdown();
|
|
1997
2000
|
this.searchInput.value = "+";
|
|
@@ -2732,17 +2735,31 @@ var Iti = class {
|
|
|
2732
2735
|
//* Validate the input val
|
|
2733
2736
|
isValidNumber() {
|
|
2734
2737
|
const val = this._getFullNumber();
|
|
2735
|
-
|
|
2736
|
-
|
|
2738
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2739
|
+
if (alphaCharPosition > -1) {
|
|
2740
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2741
|
+
const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
|
|
2742
|
+
const isValid = this._utilsIsPossibleNumber(val);
|
|
2743
|
+
return beforeAlphaIsValid && isValid;
|
|
2737
2744
|
}
|
|
2745
|
+
return this._utilsIsPossibleNumber(val);
|
|
2746
|
+
}
|
|
2747
|
+
_utilsIsPossibleNumber(val) {
|
|
2738
2748
|
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
|
|
2739
2749
|
}
|
|
2740
2750
|
//* Validate the input val (precise)
|
|
2741
2751
|
isValidNumberPrecise() {
|
|
2742
2752
|
const val = this._getFullNumber();
|
|
2743
|
-
|
|
2744
|
-
|
|
2753
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2754
|
+
if (alphaCharPosition > -1) {
|
|
2755
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2756
|
+
const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
|
|
2757
|
+
const isValid = this._utilsIsValidNumber(val);
|
|
2758
|
+
return beforeAlphaIsValid && isValid;
|
|
2745
2759
|
}
|
|
2760
|
+
return this._utilsIsValidNumber(val);
|
|
2761
|
+
}
|
|
2762
|
+
_utilsIsValidNumber(val) {
|
|
2746
2763
|
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
|
|
2747
2764
|
}
|
|
2748
2765
|
//* Update the selected country, and update the input val accordingly.
|
|
@@ -2821,7 +2838,7 @@ var intlTelInput = Object.assign(
|
|
|
2821
2838
|
//* A map from instance ID to instance object.
|
|
2822
2839
|
instances: {},
|
|
2823
2840
|
loadUtils,
|
|
2824
|
-
version: "23.8.
|
|
2841
|
+
version: "23.8.1"
|
|
2825
2842
|
}
|
|
2826
2843
|
);
|
|
2827
2844
|
var intl_tel_input_default = intlTelInput;
|
|
@@ -1956,6 +1956,9 @@ var Iti = class {
|
|
|
1956
1956
|
_initTelInputListeners() {
|
|
1957
1957
|
const { strictMode, formatAsYouType, separateDialCode, formatOnDisplay } = this.options;
|
|
1958
1958
|
let userOverrideFormatting = false;
|
|
1959
|
+
if (/\p{L}/u.test(this.telInput.value)) {
|
|
1960
|
+
userOverrideFormatting = true;
|
|
1961
|
+
}
|
|
1959
1962
|
const openDropdownWithPlus = () => {
|
|
1960
1963
|
this._openDropdown();
|
|
1961
1964
|
this.searchInput.value = "+";
|
|
@@ -2696,17 +2699,31 @@ var Iti = class {
|
|
|
2696
2699
|
//* Validate the input val
|
|
2697
2700
|
isValidNumber() {
|
|
2698
2701
|
const val = this._getFullNumber();
|
|
2699
|
-
|
|
2700
|
-
|
|
2702
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2703
|
+
if (alphaCharPosition > -1) {
|
|
2704
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2705
|
+
const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
|
|
2706
|
+
const isValid = this._utilsIsPossibleNumber(val);
|
|
2707
|
+
return beforeAlphaIsValid && isValid;
|
|
2701
2708
|
}
|
|
2709
|
+
return this._utilsIsPossibleNumber(val);
|
|
2710
|
+
}
|
|
2711
|
+
_utilsIsPossibleNumber(val) {
|
|
2702
2712
|
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberType) : null;
|
|
2703
2713
|
}
|
|
2704
2714
|
//* Validate the input val (precise)
|
|
2705
2715
|
isValidNumberPrecise() {
|
|
2706
2716
|
const val = this._getFullNumber();
|
|
2707
|
-
|
|
2708
|
-
|
|
2717
|
+
const alphaCharPosition = val.search(/\p{L}/u);
|
|
2718
|
+
if (alphaCharPosition > -1) {
|
|
2719
|
+
const beforeAlphaChar = val.substring(0, alphaCharPosition);
|
|
2720
|
+
const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
|
|
2721
|
+
const isValid = this._utilsIsValidNumber(val);
|
|
2722
|
+
return beforeAlphaIsValid && isValid;
|
|
2709
2723
|
}
|
|
2724
|
+
return this._utilsIsValidNumber(val);
|
|
2725
|
+
}
|
|
2726
|
+
_utilsIsValidNumber(val) {
|
|
2710
2727
|
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
|
|
2711
2728
|
}
|
|
2712
2729
|
//* Update the selected country, and update the input val accordingly.
|
|
@@ -2785,7 +2802,7 @@ var intlTelInput = Object.assign(
|
|
|
2785
2802
|
//* A map from instance ID to instance object.
|
|
2786
2803
|
instances: {},
|
|
2787
2804
|
loadUtils,
|
|
2788
|
-
version: "23.8.
|
|
2805
|
+
version: "23.8.1"
|
|
2789
2806
|
}
|
|
2790
2807
|
);
|
|
2791
2808
|
var intl_tel_input_default = intlTelInput;
|