반응형

# 문자열 길이 체크 로직.

  • 메세지 길이 체크 (한글) 관련 로직.
// 길이 체크 메세지(한글 2바이트)
function byteCheckMsg(str, maxbyte, msgNm){
	if (isNull(str)){
		return false;
	}

	var strByte = getByteLength(str);
	if (strByte > maxByte){
		alert(msgNm + "은" + maxByte + "까지 입력가능.\n(입력값 : " + strByte +")");
		return true;
	}
}

// 스트링 바이트 크기 계산(한글 2바이트)
function getByteLength(s, b, i, c) {
	if (!s){
		return 0;
	}

	for (b = i = 0; c = s.charCodeAt(i++); b += c >> 11 ? 2 : c >> 7 ? 2 : 1);
	eturn b;
}
반응형

+ Recent posts