diff --git a/src/components/IOC/CreateIOC/RepositoryName.js b/src/components/IOC/CreateIOC/RepositoryName.js index ddd0b470029b8ebc4e1332b068437f825e012cd8..0381116757bcaa998055b879c79fda948ccd46c8 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) {