Skip to content

Commit 7172e8a

Browse files
committed
update(Frontend v2): Input validation
1 parent 0856793 commit 7172e8a

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

frontend/src/components/steps/ProjectNameStep.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<div class="input-group">
66
<div class="label-group">
77
<label class="project-name-label" for="project-name">Project Name</label>
8-
<div class="project-name-length-indicator">{{ localProjectName.length }} / 50</div>
98
</div>
109
<div class="input-horizontal">
1110
<input
@@ -19,7 +18,7 @@
1918
:value="localProjectName"
2019
@input="handleInputChange($event)"
2120
:disabled="projectStore.isProjectNameConfirmed"
22-
maxlength="50"
21+
maxlength="100"
2322
/>
2423
<button
2524
class="confirm-btn"
@@ -40,16 +39,13 @@
4039
<script setup>
4140
import { ref, onMounted } from "vue"
4241
import { useProjectStore } from "@/stores/useProjectStore"
42+
import { isValidProjectName } from "@/utils/validation"
4343
4444
const projectStore = useProjectStore()
4545
const localProjectName = ref("asd")
4646
const showError = ref(false)
4747
const errorMessage = ref("")
4848
49-
const isValidProjectName = (name) => {
50-
return /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(name)
51-
}
52-
5349
const handleInputChange = (event) => {
5450
localProjectName.value = event.target.value
5551

frontend/src/utils/validation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const patterns = {
2+
boundedStr: /^.{1,100}$/,
3+
snakeCase: /^[a-z][a-z0-9_]*$/,
4+
enumStr: /^[a-zA-Z][a-zA-Z0-9_]*$/,
5+
projectName: /^[a-zA-Z_][a-zA-Z0-9_-]*$/,
6+
}
7+
8+
export const isValidProjectName = (value: string): boolean => {
9+
return patterns.boundedStr.test(value) && patterns.projectName.test(value)
10+
}

0 commit comments

Comments
 (0)