var _common_divBytes = 3; //유니코드 한글자당 byte 수 /*************************************************************************************************** * 함수 재정의 **************************************************************************************************/ /* valid 함수 호출시 기존에 dialog가 띄워져 있다면 close 하는 로직을 추가한다. */ (function(){ // Store a reference to the original remove method. var originalValidMethod = $.validator.prototype.valid; // Define overriding method. $.validator.prototype.valid = function(){ //Dialog 가 이미 띄워져 있다면 종료한다. common_validateCloseDialog(); // Execute the original method. return originalValidMethod.apply( this, arguments ); }; })(); /* 기본 제공 되는 validation 함수 •required – Makes the element required. •remote – Requests a resource to check the element for validity. •minlength – Makes the element require a given minimum length. •maxlength – Makes the element require a given maxmimum length. •rangelength – Makes the element require a given value range. •min – Makes the element require a given minimum. •max – Makes the element require a given maximum. •range – Makes the element require a given value range. •email – Makes the element require a valid email •url – Makes the element require a valid url •date – Makes the element require a date. •dateISO – Makes the element require an ISO date. •number – Makes the element require a decimal number. •digits – Makes the element require digits only. •creditcard – Makes the element require a credit card number. •equalTo – Requires the element to be the same as another one */ /*************************************************************************************************** * 사용자 정의 Validation 추가 **************************************************************************************************/ $.validator.addMethod( "greaterOrEqualThan", function(value, element, params) { //params[0] : 비교할 컴포넌트 validLabel(String) //params[0] : 비교할 컴포넌트 id(String) var retValue = true; //비교할 두 값이 존재하여하고 모두 숫자여야 한다. if (value != "" && $("#" + params[1]).val() != "" && !isNaN(value) && !isNaN($("#" + params[1]).val())) { retValue = parseFloat(value) >= parseFloat($("#" + params[1]).val()); } return retValue; }, $.validator.format("Input greater than or equals {0}") //{0}의 값보다 같거나 큰 값을 입력하십시오. ); $.validator.addMethod( "maxlengthEx", function(value, element, params) { //params[0] : 한글 최대 입력 자리수 //params[1] : 영문 최대 입력 자리수 var retValue = true; //비교할 두 값이 존재하여하고 모두 숫자여야 한다. if (value != "" && !isNaN(params[1])) { retValue = common_validateCheckByte(value) <= params[1]; } return retValue; }, $.validator.format("Can allow Korean {0} character English {1} character.") //한글 {0}자, 영문 {1)자까지 입력 가능합니다. ); $.validator.addMethod( "notInputKorean", function(value, element, params) { return common_validateNotKorean(value); }, $.validator.format("Can not be input the Korean. Please try again.") //한글은 입력할 수 없습니다. 다시 입력해 주십시요. ); $.validator.addMethod( "dateYYYYMMDD", function(value, element, params) { var retValue = true; if (value != "") { retValue = common_isDate(value); } return retValue; }, $.validator.format("It does not match the date format (YYYYMMDD).") //날짜형식(YYYYMMDD)에 맞지 않습니다. ); $.validator.addMethod( "compareFrToDate", function(value, element, params) { //params[0] : 비교할 컴포넌트 validLabel(String) //params[1] : 비교할 컴포넌트 id(String) var retValue = true; //시작일자와 종료일자가 모두 입력되었는지 체크 if (value != "" && $("#" + params[1]).val() != "") { var toDateArray = value.split("-"); var frDateArray = $("#" + params[1]).val().split("-"); //일자 형식(YYYY-MM-DD)을 올바르게 입력한지 체크 if(toDateArray.length == 3 && frDateArray.length == 3){ var toDate = new Date(toDateArray[0],toDateArray[1],toDateArray[2]).valueOf(); var frDate = new Date(frDateArray[0],frDateArray[1],frDateArray[2]).valueOf(); retValue = toDate >= frDate ; }; } return retValue; }, $.validator.format("The start date is greater than the termination date.") //시작일자가 종료일자 보다 큽니다. ); $.validator.addMethod( "phonenumber", function(value, element, params) { //숫자를 제외한 문자를 공백으로 치환 var regex = /[^0-9]/g; value = value.split(regex).join(""); //휴대폰번호 형식인지 체크 var regexMdn = /^01([016789])([1-9]{1})([0-9]{2,3})([0-9]{4})$/; return regexMdn.test(value); }, $.validator.format("Phone number format is invalid.") //전화번호 양식이 올바르지 않습니다. ); $.validator.addMethod( "dateMMDD", function(value, element, params) { var retValue = true; if (value != "") { retValue = common_isDateMMDD(value); } return retValue; }, $.validator.format("It does not match the date format (MMDD).") //날짜형식(MMDD)에 맞지 않습니다. ); /** * 한글이 입력되어있는 경우 false 리턴 * ascii 255(ÿ)번까지는 인정하도록 함. * @param val : 비교할 문자열 * @return 체크한 결과(true 또는 false) 반환 * * @since 2004. 05. 25(전수일) */ function common_validateNotKorean(val) { if(val.length == 0){ return true; } for (var i = 0; i < val.length; i++) { if (val.charCodeAt(i) > 256) { return false; } } return true; } /** * 지정된 객체의 문자열의 길이를 계산 * * @param str : 문자값 * @return strByte : 문자길이 * @since 2004. 05. 25(전수일). */ function common_validateCheckByte(str) { var i; var strLen; var strByte; strLen = str.length; for(i=0, strByte=0;i= ' ' && str.charAt(i) <= '~' ) strByte++; else strByte += _common_divBytes; } return strByte; } /** * 인자로 받은 값을 기준으로 한글, 영문 최대자리수를 가지는 배열 리턴 * * @param pNum : 최대자리수값 * @return Array : [0]: _common_divBytes 반영된 자리수(한글), [1]: pNum 자리수(영문) * @since 2014. 05. 20(김철현). */ function common_validateGetMaxLengthArr(pNum) { return new Array(parseInt(pNum / _common_divBytes, 10), pNum); } /*************************************************************************************************** * 사용자 정의 Validation 끝. **************************************************************************************************/ /** * Server에서 리턴된 메세지 파악해서 에러 유무 리턴 * @write: 김철현 * @param pData : server에서 Return 된 정보 @return boolean : true : 에러 있음, false :에러없음 * @since: 2014.05.12 */ function common_confirmServerMessage(pData) { var retValue = false; if (pData.error_message_type) { //에러 처리 if (pData.error_message_type == "exception_session"){ //세션 만료일 경우 $(location).attr('href', "/ncs/common/forward?pageUrl=common/CommonSessionExpired"); } else if (pData.error_message_type == "exception_alert") { //함수 내 alert로 처리 함 common_validateShowDialog(pData.error_message, 'Error Message'); //오류메세지 } else if (pData.error_message_type == "exception_custom") { common_validateShowDialog(pData.error_message); } else if (pData.error_message_type == "exception_popup") { //common_validateShowDialog(pData.error_message, 'Error Message'); //오류메세지 } retValue = true; } return retValue; } /** * Form Element에 대한 validate 에러 메세지 보여주기 위한 처리 * @write: 김철현 * @param pErrorMap : key - value 쌍으로 에러가 발생한 Element id 와 Error Message를 가지고 있다. * @param pErrorList : Error Elements.. * @since: 2014.05.12 */ function common_validateFormErrors(pErrorMap, pErrorList){ //기존 내용 삭제. $("#_fromValidation").children().remove(); $.each(pErrorList, function(index, errorObj) { var parentId = $(errorObj.element).attr("validParentId"); //validParentId 에 해당하는 li tag가 존재하지 않는다면 만들어 준다. if ($("#_fromValidation").children("li#" + "li_" + parentId).length == 0) { //li Object 추가 - jQuery 1.4 이후 버전에서 지원하는 방법으로 추가 $("#_fromValidation").append($("
  • ", { id: "li_" + parentId, html: $.trim($("#" + parentId).text()) + "
    " })); //위에서 만든 li 하위에 ul추가 $("#_fromValidation").children("li#" + "li_" + parentId).append($("