aboutsummaryrefslogtreecommitdiff
path: root/uploader/input_validation.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/input_validation.py')
-rw-r--r--uploader/input_validation.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/uploader/input_validation.py b/uploader/input_validation.py
index 9abe742..88ffd8c 100644
--- a/uploader/input_validation.py
+++ b/uploader/input_validation.py
@@ -5,10 +5,12 @@ def is_empty_string(value: str) -> bool:
"""Check whether as string is empty"""
return (isinstance(value, str) and value.strip() == "")
+
def is_empty_input(value: Any) -> bool:
"""Check whether user provided an empty value."""
return (value is None or is_empty_string(value))
+
def is_integer_input(value: Any) -> bool:
"""
Check whether user provided a value that can be parsed into an integer.
@@ -25,3 +27,26 @@ def is_integer_input(value: Any) -> bool:
__is_int__(value, 10)
or __is_int__(value, 8)
or __is_int__(value, 16))))
+
+
+def is_valid_representative_name(repr_name: str) -> bool:
+ """
+ Check whether the given representative name is a valid according to our rules.
+
+ Parameters
+ ----------
+ repr_name: a string of characters.
+
+ Checks For
+ ----------
+ * The name MUST start with an alphabet [a-zA-Z]
+ * The name MUST end with an alphabet [a-zA-Z] or number [0-9]
+ * The name MUST be composed of alphabets [a-zA-Z], numbers [0-9],
+ underscores (_) and/or hyphens (-).
+
+ Returns
+ -------
+ Boolean indicating whether or not the name is valid.
+ """
+ pattern = re.compile(r"^[a-zA-Z]+[a-zA-Z0-9_-]*[a-zA-Z0-9]$")
+ return bool(pattern.match(repr_name))