function validate(form, fields) { var lah = new FormChecker(form); if (fields) lah.setCheckFields(fields); var wmf = lah.go(); if (wmf == false) alert(lah.getErrorMessage()); return wmf; } FormChecker = function(form) { this.FUNC_MAP = { email : "this.func_email", hangul : "this.func_hangul", engonly : "this.func_engonly", number : "this.func_number", residentno: "this.func_residentno", jumin : "this.func_jumin", foreignerno:"this.func_foreignerno", bizno : "this.func_bizno", phone : "this.func_phone", telephone : "this.func_phone", homephone : "this.func_homephone", handphone : "this.func_handphone", userid : "this.func_userid", userpw : "this.func_userpw", mobile : "this.func_handphone", isdate : "this.func_isdate", isdate6 : "this.func_isdate6", engnum_ : "this.func_engnum_", trim : "this.func_trim", norchar : "this.func_norchar" } this.ERR_MSG = { system : "FormChecker Error: ", required : "필수입력항목입니다.", requirenum:"이 항목들 중에 {requirenum}개 이상의 항목이 입력되어야 합니다.", notequal : "입력된 내용이 일치하지 않습니다.", invalid : "입력된 내용이 형식에 어긋납니다.", minbyte : "입력된 내용의 길이가 {minbyte}Byte 이상이어야 합니다.", maxbyte : "입력된 내용의 길이가 {maxbyte}Byte를 초과할 수 없습니다.", mincheck : "{mincheck}개의 항목이상으로 선택하세요.", maxcheck : "{maxcheck}개의 항목이하로 선택하세요.", minselect: "{minselect}개의 항목이상으로 선택하세요.", maxselect: "{maxselect}개의 항목이하로 선택하세요.", imageonly: "이미지 파일만 첨부할 수 있습니다." } this.ERR_DO = { text : "select focus", select : "focus", check : "focus", radio : "focus", file : "focus", hidden : "" } this.ERR_SYS = '_SYSERR_'; this.fields = form.elements; this.form = form; this.errMsg = ""; } FormChecker.prototype.setForm = function(form) { this.form = form; } FormChecker.prototype.setFunc = function(map, func) { if (typeof(this.FUNC_MAP[map]) == "string") return; this.FUNC_MAP[map] = func; } FormChecker.prototype.setCheckFields = function(fields) { this.fields = []; if(typeof(fields) == 'string') this.fields = [this.form.elements[fields]]; else for(var i=0, s=fields.length; i 0) { for (var j=0; j 0 || maxbyte > 0) && (elType == "text" || elType == "hidden")) { var _tmp = el.value; var _len = el.value.length; for (j=0; j<_tmp.length; j++) { if (_tmp.charCodeAt(j) > 128) { _len++; } } if (minbyte > 0 && _len < minbyte) { return this.raiseError(el, "minbyte"); } if (maxbyte > 0 && _len > maxbyte) { return this.raiseError(el, "maxbyte"); } } if (match != null && elType != "file") { if (typeof this.form.elements[match] == "undefined") { return this.raiseError(this.ERR_SYS, "Element '"+ match +"' is not found."); } else if (el.value != this.form.elements[match].value) { return this.raiseError(el, "notequal"); } } if (option != null && !elEmpty && elType != "file") { var _options = option.split(" "); for (var j in _options) { var _func = eval(this.FUNC_MAP[_options[j]]); if (span != null) { var _value = []; for (var k=0; k 0 || maxcheck > 0) && elType == "check") { var _checks = this.form.elements[el.name]; var _num = 0; if (typeof _checks.length != "undefined") { for (var j=0; j<_checks.length; j++) { if (_checks[j].checked) { _num++; } } } else { if (_checks.checked) { _num++; } } if (mincheck > 0 && _num < mincheck) { return this.raiseError(el, "mincheck"); } if (maxcheck > 0 && _num > maxcheck) { return this.raiseError(el, "maxcheck"); } } if ((minselect > 0 || maxselect > 0) && elType == "multiselect") { var _num = 0; for (var j=0; j 0 && _num < minselect) { return this.raiseError(el, "minselect"); } if (maxselect > 0 && _num > maxselect) { return this.raiseError(el, "maxselect"); } } if (imageonly !== null && elType == "file") { var fn = el.value; if (fn != "") { var dotIndex = fn.lastIndexOf("."); var ext = fn.substring(dotIndex+1).toLowerCase(); if(ext != "jpg" && ext != "jpeg" && ext != "gif" && ext != "png") { return this.raiseError(el, "imageonly"); } } } } return true; } FormChecker.prototype.isValidElement = function(el) { return el.name && el.tagName.match(/^input|select|textarea$/i) && !el.disabled; } FormChecker.prototype.isEmpty = function(el, type) { switch (type) { case "file": case "text": case "hidden": if (el.value == null || el.value == "") { return true; } break; case "select": case "multiselect": if (el.selectedIndex == -1 || el[el.selectedIndex].value == null || el[el.selectedIndex].value == "") { return true; } break; case "check": case "radio": var elCheck = this.form.elements[el.name]; var elChecked = false; if (typeof elCheck.length != "undefined") { for (var j=0; j -1) { temp_str = temp_str.replace(str1, str2); } } return temp_str; }