Wizard: Hostname validation
Hostname validation rules can be found in the hostname man pages (`man 5 hostname`). This commit tweaks the hostname validator function so it is in line with these guidelines by limiting the length to 64 characters and also updates the error message for invalid hostnames to provide users with some additional guidance/context when an invalid hostname is provided.
This commit is contained in:
parent
5a514d1d04
commit
b4932d6a44
2 changed files with 14 additions and 6 deletions
|
|
@ -92,10 +92,14 @@ export const isNtpServerValid = (ntpServer: string) => {
|
|||
};
|
||||
|
||||
export const isHostnameValid = (hostname: string) => {
|
||||
if (hostname !== '') {
|
||||
return /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/.test(
|
||||
hostname
|
||||
);
|
||||
switch (true) {
|
||||
case hostname.length > 63:
|
||||
return false;
|
||||
case hostname !== '':
|
||||
return /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/.test(
|
||||
hostname
|
||||
);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue