Skip to content

Commit

Permalink
fix: validateMemberName함수가 유효한 이름인지를 확인하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pakxe committed Dec 17, 2024
1 parent 589d3c5 commit 4c0cfdb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions client/src/utils/validate/validateMemberName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ import RULE from '@constants/rule';

import {ValidateResult} from './type';

const validateMemberName = (name: string): ValidateResult => {
let errorMessage = null;
const validateMemberName = (name: string) => {
const slicedName = name.trim().slice(0, RULE.maxMemberNameLength);

const validateOnlyString = () => {
return REGEXP.memberName.test(name);
return REGEXP.memberName.test(slicedName);
};

const validateLength = () => {
return name.length <= RULE.maxMemberNameLength;
return slicedName.length > 0;
};

if (validateOnlyString() && validateLength()) {
return {isValid: true, errorMessage: null};
}
const getErrorMessage = () => {
if (!validateOnlyString()) return ERROR_MESSAGE.memberNameFormat;
if (name.length > RULE.maxMemberNameLength) return ERROR_MESSAGE.memberNameLength;
return null;
};

return {isValid: false, errorMessage: errorMessage || ERROR_MESSAGE.memberName};
return {
memberName: slicedName,
isValid: validateLength() && validateOnlyString(),
errorMessage: getErrorMessage(),
};
};

export default validateMemberName;

0 comments on commit 4c0cfdb

Please sign in to comment.