Skip to content

Commit cb7dd2a

Browse files
authored
Merge pull request #284 from MultiDirectoryLab/feature/MD-1424
MD-1424
2 parents acaa37f + 89c6068 commit cb7dd2a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

projects/multidirectory-app/src/app/core/validators/ip-universal.directive.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ import { translate } from '@jsverse/transloco';
1515
})
1616
export class UniversalIpValidatorDirective implements Validator {
1717
readonly errorLabel = input(translate('error-message.ip-valid'));
18-
ipPattern = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:-(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))?(?:\/(?:[0-9]|[1-2][0-9]|3[0-2]))?(?:,\s*(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:-(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))?(?:\/(?:[0-9]|[1-2][0-9]|3[0-2]))?)*$/;
18+
ipPattern = new RegExp(
19+
'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:-(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))?(?:\\/(?:[0-9]|[1-2][0-9]|3[0-2]))?$',
20+
);
1921

2022
validate(control: AbstractControl): ValidationErrors | null {
21-
return this.ipPattern.test(control.value) ? null : { IpAddress: this.errorLabel() };
23+
const value = control.value;
24+
// возможно, передан список IP через запятую
25+
const extractedIps: string[] = value.replace(/\s/g, '').split(',');
26+
27+
return extractedIps.every((ip) => this.ipPattern.test(ip)) ? null : { IpAddress: this.errorLabel() };
2228
}
2329
}

0 commit comments

Comments
 (0)