//인자값이 숫자인지 판단 var validNum = /^[-]?\d+(?:[.]\d+)?$/; var validCharZero = /.*\..*0$/; //var validCharZeroSt = /^0\d/; function checkNum(str, valueType) { if(str.value.indexOf('!#')>-1|| str.value.indexOf('#!')>-1|| str.value.indexOf('!@')>-1|| str.value.indexOf('@!')>-1|| str.value.indexOf('!`')>-1|| str.value.indexOf('`!')>-1 ){ alert('!#,#!,!@,@!,!`,`! 기호는 사용할 수 없습니다. 다시 입력해 주세요'); if(valueType.search("2") != -1) { str.value=0; }else{ str.value=''; } str.focus(); } if(valueType.search("2") != -1) { if(isNaN(str.value) || str.value == '' || str.value == ' ' || !(validNum.test(str.value))){ alert(str.value+" 는 문자 또는 공백입니다. \n숫자를 입력하세요."); str.value=0; str.focus(); } }else if(valueType.search("1") != -1){ if(validCharZero.test(str.value)){ alert(str.value + " 문자의 끝에 숫자 0을 지원하지 않습니다. \n0 이외의 다른 숫자나 기호를 입력하세요"); str.value = str.value+"."; str.focus(); // }else if(validCharZeroSt.test(str.value)){ // alert(str.value + " 숫자형식의 첫글자에 0을 지원하지 않습니다. \n0 이외의 다른 숫자나 기호를 입력하세요"); // str.value = "`"+str.value; // str.focus(); } } if( typeof(fn_checkValue) == "function" ) fn_checkValue(str, valueType); } function checkMaxNum(num, minNum, maxNum){ if(num.value < minNum || num.value > maxNum){ alert(minNum+" ~ "+ maxNum +" 사이의 값을입력하여 주세요."); num.value=minNum; num.focus(); } } //인자값이 10보다 작을때 앞에 0을 붙여줌 function changeNumber(num){ return (num > 9) ? num : "0" + num; } //공백제거 function spaceAll(str){ var index, len; while(true){ index = str.indexOf(" "); // 공백이 없으면 종료합니다. if (index == -1) break; // 문자열 길이를 구합니다. len = str.length; // 공백을 잘라냅니다. str = str.substring(0, index) + str.substring((index+1),len); } return str; } /** * 문자열의 byte 길이를 계산한다. * UTF-8 환경에서 한글은 3 byte 이다. 영문, 특수기호는 1 byte. * 2014.12.01 by YOUNGJUN,CHO * @param {type} str * @returns {Number} */ function getByteSize(str) { if (str === null || str.length === 0) { return 0; } var size = 0; for (var i = 0 ; i < str.length ; i++) { var charCode = str.charAt(i).charCodeAt(0); if (charCode <= 0x00007F) { size += 1; } else if (charCode <= 0x0007FF) { size += 2; } else if (charCode <= 0x00FFFF) { size += 3; } else { size += 4; } } return size; }