diff --git a/src/types/BlockTypes.ts b/src/types/BlockTypes.ts
index 07ac009..a1548dc 100644
--- a/src/types/BlockTypes.ts
+++ b/src/types/BlockTypes.ts
@@ -28,7 +28,7 @@ export type WebServerBlock = Block & {
imageTags: string;
username: string | undefined;
secrets: string | undefined;
- containerPort: number;
+ containerPort: number|undefined;
};
connectionMetadata: {
dbRef: string;
diff --git a/src/utils/InputUtils.ts b/src/utils/InputUtils.ts
new file mode 100644
index 0000000..050c3c0
--- /dev/null
+++ b/src/utils/InputUtils.ts
@@ -0,0 +1,69 @@
+import { InputStatus } from "antd/es/_util/statusUtils";
+
+export type InputRuledProps = {
+ type: string,
+ value?: string,
+ maxLength?: number,
+ minLength?: number,
+ placeholder?:string,
+}
+
+export type ErrorType = 'length_min' | 'length_max' | 'type_err';
+
+export type CheckInputType = {
+ status: InputStatus,
+ errorType?: ErrorType,
+ message: string,
+}
+// 조건에 맞는 input인지 확인하는 함수
+export const checkInput = ({ ...props }: InputRuledProps): CheckInputType => {
+ // 최소 길이 확인
+ if (props.minLength && props.value!.length < props.minLength) {
+ return { status: 'error', errorType: 'length_min', message: `최소 ${props.minLength}자 이상 입력해주세요.` }
+ }
+ else if (props.maxLength && props.value!.length > props.maxLength) {
+ return { status: 'error', errorType: 'length_max', message: `최대 ${props.maxLength}자 이하로 입력해주세요.` };
+ }
+
+ // length 확인이 완료된 경우, type 확인
+ // type 확인
+
+ // 모든 조건을 충족하는 경우
+ return typeCheck(props.value!, props.type);
+}
+
+const typeCheck = (value: string, type: string): CheckInputType => {
+ var result:CheckInputType = { status: '', message: '' };
+ switch (type) {
+ case 'number':
+ if (isNaN(Number(value))) {
+ result = { status: 'error', message: '숫자만 입력해주세요.' };
+ }
+ break;
+ case 'email':
+ const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
+ if (!emailRegex.test(value)) {
+ result = { status: 'error', message: '이메일 형식으로 입력해주세요.(ex : abc@kangdroid.com)' };
+ }
+ break;
+ case 'string':
+ const stringRegex = /^[a-zA-Z가-힣0-9\s]*$/;
+ if (!stringRegex.test(value)) {
+ result = { status: 'error', message: '특수문자는 입력할 수 없습니다.' };
+ }
+ break;
+ case 'english':
+ const englishRegex = /^[a-zA-Z]*$/;
+ if (!englishRegex.test(value)) {
+ result = { status: 'error', message: '영어만 입력해주세요.' };
+ }
+ break;
+ default:
+ result = { status: '', message: '' };
+ }
+
+ if(result!.status === 'error')
+ result.errorType = 'type_err';
+
+ return result;
+}
\ No newline at end of file
diff --git a/src/utils/validators.ts b/src/utils/validators.ts
new file mode 100644
index 0000000..1417075
--- /dev/null
+++ b/src/utils/validators.ts
@@ -0,0 +1,99 @@
+import { InputRuledProps, checkInput } from "./InputUtils";
+
+// Form.Item의 rules의 validator에서 input의 값을 검증
+// 값에 따라 Form 제출을 reject, resolve할 수 있음.
+export const validateInput = ({ ...props }: InputRuledProps) => {
+ const checkResult = checkInput({ ...props });
+ console.log(checkResult);
+ if (checkResult.status === 'error') {
+ return Promise.reject(checkResult.message);
+ } else {
+ return Promise.resolve();
+ }
+};
+
+// Input 형태 정의
+export const validationConfig = {
+ channelName: {
+ maxLength: 40,
+ minLength: 1,
+ type: 'string'
+ },
+ channelDescription: {
+ maxLength: 200,
+ minLength: 1,
+ type: 'string'
+ },
+ channelProfileImg: {
+ type: 'image'
+ },
+ userName: {
+ maxLength: 40,
+ minLength: 1,
+ type: 'string'
+ },
+ userEmail: {
+ maxLength: 320,
+ minLength: 1,
+ type: 'email'
+ },
+ userImg: {
+ type: 'image'
+ },
+ sketchName: {
+ maxLength: 40,
+ minLength: 1,
+ type: 'string'
+ },
+ sketchDescription: {
+ maxLength: 300,
+ minLength: 1,
+ type: 'string'
+ },
+ blockTitle: {
+ maxLength: 20,
+ minLength: 1,
+ type: 'string'
+ },
+ blockDescription: {
+ maxLength: 200,
+ minLength: 1,
+ type: 'string'
+ },
+ "aws-static-AccessKey": {
+ maxLength: 40,
+ type: 'string'
+ },
+ "aws-static-SecretKey": {
+ maxLength: 40,
+ type: 'string'
+ },
+ "aws-static-Region": {
+ maxLength: 30,
+ type: 'string'
+ },
+ "azure-static-ClientId": {
+ maxLength: 60,
+ type: 'string'
+ },
+ "azure-static-ClientSecret": {
+ maxLength: 60,
+ type: 'string'
+ },
+ "azure-static-SubscriptionId": {
+ maxLength: 60,
+ type: 'string'
+ },
+ "azure-static-TenantId": {
+ maxLength: 60,
+ type: 'string'
+ },
+ "azure-static-Region": {
+ maxLength: 40,
+ type: 'string'
+ },
+ searchInput:{
+ maxLength: 200,
+ type: 'string'
+ }
+};
\ No newline at end of file