Skip to content

Commit 2f735fa

Browse files
Add port validation
1 parent 758e330 commit 2f735fa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/module/connection/create/connection-creator.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ const connectionUrlValidator: ValidatorFn = (control: AbstractControl<string>) =
3232
};
3333

3434
const addressValidator: ValidatorFn = (control: AbstractControl<string>) => {
35-
if (control.value.startsWith(`http://`) || control.value.startsWith(`https://`)) return null;
36-
else return { errorText: `Please specify http:// or https://` };
35+
const value = control.value;
36+
if (!value.startsWith(`http://`) && !value.startsWith(`https://`)) {
37+
return { errorText: `Please specify http:// or https://` };
38+
}
39+
// Check for port format: http(s)://<address>:<port>
40+
// Match http(s):// followed by address content, then :port (digits)
41+
const portPattern = /^https?:\/\/.+:\d+/;
42+
if (!portPattern.test(value)) {
43+
return { errorText: `Format: http(s)://<address>:<port>` };
44+
}
45+
return null;
3746
}
3847

3948
@Component({

0 commit comments

Comments
 (0)