유저테스트 중 이모티콘(이모지)를 입력하면 부하가 상당하다는 이야기를 들었다. 과연 하나에 몇 바이트나 되길래 부하가 상당하다고 하는걸까?
대부분의 이모지는 4바이트로 표현된다고 한다.
[ 참고자료 ]
https://codingbroker.tistory.com/119
https://blog.hoseung.me/2022-08-25-emoji-and-unicode
유니코드 범위
https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs#Emoji_modifiers
암튼 그래서 이모지가 들어가는 것을 방지하기 위해서 열심히 joi 방법을 찾았다.
//영어, 한글, 숫자만 입력가능 ()
const regex = /^[ㄱ-ㅎ가-힣a-zA-Z0-9]+$/;
const createPostsSchema = Joi.object({
content: Joi.string().min(10).max(2000).regex(regex).messages({
"string.min": "content를 10자 이상으로 작성해주세요.",
"string.max": "content를 2000자 이하으로 작성해주세요.",
"string.empty": "content를 입력해주세요.",
"string.pattern.base": "한글, 영어, 숫자만 입력해주세요."
}),
이렇게 하면 regex에 의해서 string.pattern.base 오류 메시지가 뜨면서 영어, 한글, 숫자만 입력하도록 가능하다.
근데 요즘엔 이모지들 많이 사용하는데 이모지 사용은 하되 개수에 제한을 두는것도 방법이지 않을까.