/* sky.form.checker.js 2007-04-18 ~ 2008-06-02 Seo, Jaehan @dependence sky.base.js [ SYNOPSYS ] function init() { var fc = new Form.Checker({ form : 'formIdOrName', message : '%s in invalid.', // optional. default message format preFunc : preCheckFunction, // optional. postFunc : postCheckFunction, // optional. }); // add check list fc.check('age', /^[0-9]+$/, 'Age', '%s must be number.'); // RegExp object fc.check('email', checkEmail, 'Email'); // function fc.check('passwd', 'length:4,8', 'Password'); // option string // for lib.validate.js style fc.scan(); } $(window).on('load', init); [ options for Form.Checker.add() ] - RegExp object - function - option string . length:[min,]max - string length . byte:[min,]max - string byte . range:[min,]max - number range . check:[min,]max - checkbox check count // add . select:[min,]max - selectbox select count // add . alter[:max] - alternative . glue:string - glue . empty - check if empty. (default) . trim - trim value (not applied to original) . apply:element - apply value to another element . match:element - compare elements value . email, homepage, url, jumin, bizno, phone, mobile - pre defined check function */ if (typeof Form == 'undefined') { Form = {}; } Form.Checker = Class({ init : function(options) { jQuery.extend(this, { form : null, auto : true, message : '%s 항목이 바르지 않습니다.', preFunc : null, postFunc : null, useHiddenAct : false, useMarking : false, markingAvail : false, markingHTML : '*', markingType : 1 // 0:left, 1:right }, options); this.pre_message = ''; this.checkList = {}; // 이메일삭제 2018-09-05 김여로 주석 this.funcList = { //'email' : this.checkEmail, 'homepage' : this.checkHomepate, 'url' : this.checkUrl, 'jumin' : this.checkJumin, 'foreign' : this.checkForeign, 'bizno' : this.checkBizNo, 'phone' : this.checkPhone, 'mobile' : this.checkMobile, 'number' : this.checkNumber, 'date' : this.checkDate, 'password' : this.checkPassword }; var self = this; this.setForm(this.form); this.onCheck = this.onSubmit.bindForEvent(this); if (this.auto) { jQuery(this.form).on('submit', this.onCheck); } if (this.useMarking) { var self = this; jQuery(document).ready(function() { self.markingAvail = true; self.doMarkingAll(); }); } }, setForm : function(form) { if (typeof form == 'string') { this.form = document.forms[form]; } else if (typeof form.tagName == 'string' && form.tagName.toLowerCase() == 'form') { this.form = form; } else { this.form = null; } this.form.Checker = this; this.form.setAttribute("autocomplete", "off"); // for Firefox forcus exception error return this.form; }, addCheck : function(element, option, name, message) { element = this.getElement(element); if (!element) { return false; // error } var key = element.id || element.name || element[0].id || element[0].name; if (!key) { return false; // error } if (this.checkList[key]) { this.checkList[key]['enable'] = true; } else { if (!(element instanceof Array)) element = [element]; this.checkList[key] = { enable : true, element : element, option : this.parseOption(option), name : name, message : message || this.message }; } if (this.markingAvail) { this.doMarking(key); } return true; }, delCheck : function(element) { element = this.getElement(element); if (!element) { return false; // error } var key = element.id || element.name || element[0].id || element[0].name; if (this.checkList[key]) { this.checkList[key]['enable'] = false; if (this.markingAvail) { this.doMarking(key); } } }, toggle : function(element) { element = this.getElement(element); if (!element) { return false; // error } var key = element.id || element.name || element[0].id || element[0].name; if (this.checkList[key]) { this.checkList[key]['enable'] = !this.checkList[key]['enable']; if (this.markingAvail) { this.doMarking(key); } } }, doMarkingAll : function() { for (var x in this.checkList) { this.doMarking(x); } }, doMarking : function(element) { element = this.getElement(element); if (!element) { return false; // error } var key = element.id || element.name || element[0].id || element[0].name; var check = this.checkList[key]; if (!check) { return; } var cell = jQuery(element).parents('td:first').prev('th, td'); if (jQuery(cell).length) { if (check.enable) { if (!jQuery(cell).prop('required')) { var text = jQuery(cell).html(); if (this.markingType == 1) { var html = text + ' ' + this.markingHTML; } else { var html = this.markingHTML + ' ' + text; } jQuery(cell).prop('required', true).prop('text', text).html(html); } } else { if (jQuery(cell).prop('required')) { jQuery(cell).html(jQuery(cell).prop('text')).removeProp('required').removeProp('text'); } } } }, onSubmit : function(evt) { jQuery.eventStop(evt); this.doSubmit(); }, doSubmit : function() { if (this.doCheck()) { // hidden frame if (this.useHiddenAct){ this.drawHiddenFrame(); this.form.target = '__hidden_frame_for_act__'; } if (typeof this.onSuccess == 'function') { this.onSuccess.call(this); } else { if (this.form.useSSL) { // apply SSL this.doSSLSubmit(); } else { this.form.submit(); } } } }, doSSLSubmit : function() { var list = this.form.elements; if (this.useHiddenAct){ // hidden act일경우 현재 페이지에 만들어진 wmssl form을 제거한다.(wmssl에 의해 재생성된다.) jQuery('form[name="__sys_form_whoisssl_plain"]').remove(); } for (var i=0; i= 2) { option[0] = parseInt(option[0], 10); option[1] = parseInt(option[1], 10); flag = ((!option[0] || cmp >= option[0]) && (!option[1] || cmp <= option[1])) ? true : false; } // etc } else { switch (key) { case 'empty' : for (var j=0; j= 128) { byteTotal += 2; } else { byteTotal++; } } return byteTotal; }, parseOption : function(option) { if (!(option instanceof Array)) option = [option]; var result = {}; var index = 0; for (var i=0; i 1){ for (var i=0; i