@hmcts/opal-frontend-common 0.0.86 → 0.0.87
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
function optionalPhoneNumberValidator() {
|
|
1
|
+
function optionalPhoneNumberValidator(allowedLengths = [11]) {
|
|
2
2
|
const numericPattern = /^[\d\s]*$/;
|
|
3
3
|
return (control) => {
|
|
4
4
|
if (control.value) {
|
|
5
5
|
const valueWithoutSpaces = control.value.replaceAll(/\s+/g, '');
|
|
6
6
|
const isValidPattern = numericPattern.test(control.value);
|
|
7
|
-
const isValidLength = valueWithoutSpaces.length
|
|
7
|
+
const isValidLength = allowedLengths.includes(valueWithoutSpaces.length);
|
|
8
8
|
const valid = isValidPattern && isValidLength;
|
|
9
9
|
return valid ? null : { phoneNumberPattern: { value: control.value } };
|
|
10
10
|
}
|
package/package.json
CHANGED