-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce for client the network name validation
- Loading branch information
Robert Hoppe
committed
Feb 25, 2024
1 parent
b55fb13
commit 8155110
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// this file is used for validating network data and properties | ||
|
||
package network | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
// ValidateNetworkName validates a given network name | ||
func ValidateNetworkName(name string) error { | ||
if len(name) > 63 || name == "" { | ||
return fmt.Errorf("name bust be non-empty and < 64 characters") | ||
} | ||
|
||
exp := `^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$` | ||
r := regexp.MustCompile(exp) | ||
if !r.MatchString(name) { | ||
return fmt.Errorf("invalid cluster name. valid name is of: %s", exp) | ||
} | ||
return nil | ||
} |