diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index 08269f6186d65845ca11db33d4e0a84d1f4fc71b..78bf4c28d02a57515b366c9a38608a5de336991d 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)." + )