From d5738f054d9fbd77beb1f0c46a6049576a8398c7 Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Wed, 3 Jul 2024 12:55:25 +0200
Subject: [PATCH] Enhanced readablity for repo name rules

---
 src/components/IOC/CreateIOC/RepositoryName.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/components/IOC/CreateIOC/RepositoryName.js b/src/components/IOC/CreateIOC/RepositoryName.js
index ddd0b470..03811167 100644
--- a/src/components/IOC/CreateIOC/RepositoryName.js
+++ b/src/components/IOC/CreateIOC/RepositoryName.js
@@ -7,7 +7,11 @@ const propTypes = {
   onRepoNameChange: func
 };
 
-const REPO_NAME_REGEX = "^(?=.{4,20}$)[a-z0-9]+([a-z0-9_-]+)*[a-z0-9]$";
+// match from beginning to end
+// starts with an alpha numeric character (a-Z 0-9)
+// followed by 0 or more combinations of alphanumeric characters or - or _
+// ends with an alpha numeric character (a-Z 0-9)
+const REPO_NAME_REGEX = "^[a-z0-9]+([a-z0-9_-]+)*[a-z0-9]$";
 
 export const RepositoryName = ({ repoName, onRepoNameChange }) => {
   const [valid, setValid] = useState(repoName || repoName.length === 0);
@@ -15,7 +19,10 @@ export const RepositoryName = ({ repoName, onRepoNameChange }) => {
   const handleNameChange = useCallback(
     (e) => {
       const reg = new RegExp(REPO_NAME_REGEX);
-      const valid = reg.test(e.target.value);
+      const hasValidCharacters = reg.test(e.target.value);
+      const hasValidLength =
+        e.target.value.length >= 4 && e.target.value.length <= 20;
+      const valid = hasValidCharacters && hasValidLength;
       setValid(valid);
 
       if (valid) {
-- 
GitLab