From 0aaf331a02f7bc72b8051b59a68790c6fdb1dab6 Mon Sep 17 00:00:00 2001 From: Hakan Calim <hakan.calim@fau.de> Date: Wed, 1 Nov 2023 21:05:28 +0100 Subject: [PATCH] NAT-328: Moved the site name validation to this file --- gso/utils/helpers.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index 08269f61..78bf4c28 100644 --- a/gso/utils/helpers.py +++ b/gso/utils/helpers.py @@ -179,3 +179,18 @@ def validate_country_code(country_code: str) -> str: return country_code except LookupError: raise ValueError("Invalid or non-existent country code, it must be in ISO 3166-1 alpha-2 format.") + + +def validate_site_name(site_name: str) -> str: + """Validate the site name. + + The site name must consist of three uppercase letters (A-Z) followed by an optional single digit (0-9). + """ + pattern = re.compile(r"^[A-Z]{3}[0-9]?$") + if pattern.match(site_name): + return site_name + else: + raise ValueError( + "Enter a valid site name. It must consist of three uppercase letters (A-Z) followed by an optional single " + "digit (0-9)." + ) -- GitLab