582 lines
18 KiB
JavaScript
582 lines
18 KiB
JavaScript
/**
|
|
***************************************************************************
|
|
프로그램 정보
|
|
***************************************************************************
|
|
|
|
* Title : Es폼체크
|
|
|
|
* File : ESvalidator.js
|
|
|
|
* Date : 2010-10-01
|
|
|
|
* Update History :
|
|
|
|
* Author :
|
|
- 수리도랑
|
|
|
|
* E-Mail :
|
|
- impactlife@naver.com
|
|
|
|
* Summary :
|
|
|
|
jquery 필요함 - 테스트환경 jquery-1.3.2
|
|
|
|
< 지원 태그목록 >
|
|
label : string [캡션],
|
|
required : true|false,
|
|
memberid : true|false,
|
|
minlength : int,
|
|
eqaul : string [target element name],
|
|
hangul : true|false [완성형한글],
|
|
hangul2 : true|false [조합형한글 : 자음모음만 있는것도 가능],
|
|
email : string [이메일],
|
|
phonenumber : string [전화번호 : 111-1111-1111 형식]
|
|
groupcheck : true|false [radio, checkbox 에서 하나이상 필수 입력이 요구될때],
|
|
jumin : true|false [주민번호 : '-' 포함도 가능]
|
|
taxno : true|false [사업자번호 : '-' 포함도 가능]
|
|
zipcode : true|false [우편번호 : 111-111 형식]
|
|
uniq : string [이미 존재하는 값인지 체크 : ajax 로 호출할 url,
|
|
ajax 호출결과는 문자열 'true'(사용해도됨) 또는 'false'(사용할 수 없음)여야 함]
|
|
|
|
* Example :
|
|
|
|
<form name="formname" id='formname' action="http://www.naver.com" method="post">
|
|
아이디 : <input type="text" name="mb_id" class="button {label:'회원아이디',required:true,memberid:true,minlength:4,uniq:'existcheck.php'}" /><br />
|
|
비밀번호 : <input type="text" name="mb_pw" class="{label:'비밀번호',required:true,minlength:4}" /><br />
|
|
비밀번호확인 : <input type="text" name="mb_pw2" class="{label:'비밀번호확인',equal:'mb_pw'}" /><br />
|
|
이름 : <input type="text" name="mb_name" class="{label:'이름',required:true,hangul2:true}" /><br />
|
|
이메일 : <input type="text" name="mb_email" class="{label:'이메일',email:true}" /><br />
|
|
전화번호 : <input type="text" name="mb_tel" class="{label:'전화번호',required:true,phonenumber:true}" /><br />
|
|
취미 : <input type="checkbox" name="mb_recemail[]" value="축구" class="{label:'취미',groupcheck:true}" />축구,
|
|
<input type="checkbox" name="mb_recemail[]" value="야구" />야구,
|
|
<input type="checkbox" name="mb_recemail[]" value="농구" />농구
|
|
<br />
|
|
가입선물:
|
|
<input type="radio" name="mb_gift" class="{label:'가입선물',groupcheck:true}" value="된장" />된장,
|
|
<input type="radio" name="mb_gift" value="고추장" />고추장,
|
|
<input type="radio" name="mb_gift" value="쌈장" />쌈장
|
|
<br />
|
|
직업 : <select name="mb_job" class="{label:'직업',required:true}">
|
|
<option value=''>== 선택 ==</option>
|
|
<option value='잡부'>잡부</option>
|
|
<option value='후로그래머'>후로그래머</option>
|
|
<option value='디자이너'>디자이너</option>
|
|
</select><br />
|
|
신체포기각서 : <input type="checkbox" name="mb_agree" class="{label:'신체포기각서',required:true}" /> 동의합니다<br />
|
|
주민번호 : <input type="text" name="mb_jumin" class="{label:'주민번호',required:true,jumin:true,minlength:13}" /><br />
|
|
사업자등록번호 : <input type="text" name="mb_taxno" class="{label:'사업자등록번호',required:true,taxno:true}" /><br />
|
|
우편번호 : <input type="text" name="mb_zipcode" class="{label:'우편번호',required:true,zipcode:true}" /><br />
|
|
<input type="submit" value='aaa' />
|
|
</form>
|
|
****************************************************************************
|
|
**/
|
|
|
|
(function($){
|
|
|
|
$.validator = function() {
|
|
this.form = null;
|
|
this.error = {result:false,type:'alert',msg:null}
|
|
};
|
|
|
|
$.extend($.validator, {
|
|
|
|
//===========================================================================
|
|
// Prototype
|
|
//===========================================================================
|
|
prototype:{
|
|
|
|
validCheck:function(f){
|
|
this.form = f;
|
|
var validator = this;
|
|
var ele = f.elements;
|
|
for(var i=0;i<ele.length;i++){
|
|
try
|
|
{
|
|
if ($(ele[i]).attr('type') != 'select-multiple') {
|
|
ele[i].value = $.validator.bothTrim(ele[i].value);
|
|
}
|
|
|
|
if(!validator.valid(ele[i])) return false;
|
|
}
|
|
catch (e)
|
|
{
|
|
// return false;
|
|
}
|
|
}
|
|
},
|
|
|
|
valid:function(ele){
|
|
var validator = this;
|
|
var pattern = /({.+?})/;
|
|
var cvalue = $(ele).attr('class');
|
|
var cls = cvalue.match(pattern);
|
|
if(cls != null){
|
|
//클래스 개수만큼
|
|
for(var i=0;i<cls.length;i++){
|
|
var orule = eval('(' + cls[i] + ')');
|
|
//클래스안의 룰 개수만큼 루프
|
|
for(var key in orule){
|
|
if(key=='label') continue;
|
|
if(!orule.required && $(ele).val()=='') continue;
|
|
var mtdname = 'val' + $.validator.ucfirst(key);
|
|
var existMethod = this.hasMethod(mtdname);
|
|
if(existMethod==undefined){
|
|
this.error.result = false;
|
|
this.error.msg = 'class 속성 안에 존재하지 않는 메소드를 호출하였습니다 [' + key + ']';
|
|
}else{
|
|
|
|
validator[mtdname](ele, orule);
|
|
}
|
|
|
|
if(this.error.result){
|
|
this.invalidProcess(ele, orule);
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
return true;
|
|
},
|
|
|
|
hasMethod:function(methodname){
|
|
return this && this[methodname] && this[methodname] instanceof Function;
|
|
},
|
|
|
|
//처리하고 싶은데로 변경하면 됨(지금은 걍 alert창)
|
|
invalidProcess:function(ele, o){
|
|
$('.es_error').remove();
|
|
if(this.error.type == 'print'){
|
|
$(ele.parentNode).append("<span class='es_error' style='color:blue;font-weight:bold'>" + this.error.msg + "</span>");
|
|
$(ele).focus();
|
|
}else{
|
|
alert(this.error.msg);
|
|
$(ele).focus();
|
|
}
|
|
this.initError();
|
|
},
|
|
|
|
initError:function(){
|
|
this.error.result = false;
|
|
this.error.type = 'alert';
|
|
this.error.msg = null;
|
|
},
|
|
|
|
valRequired:function(ele, o){
|
|
if(!o.required) return;
|
|
|
|
if($(ele).attr('type')=='checkbox' || $(ele).attr('type')=='radio'){
|
|
if(!ele.checked){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 필수 체크 항목입니다';
|
|
}
|
|
}else if($(ele).attr('type')=='textarea'){
|
|
|
|
if($(ele).attr('name') == 'b_content'){
|
|
oEditors.getById["b_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('b_content').value);
|
|
}
|
|
|
|
|
|
if($(ele).attr('name') == 'bcm_comment'){
|
|
oEditors.getById["bcm_comment"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('bcm_comment').value);
|
|
}
|
|
|
|
if($(ele).attr('name') == 'h_content'){
|
|
oEditors.getById["h_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('h_content').value);
|
|
}
|
|
|
|
if($(ele).attr('name') == 'e_content'){
|
|
oEditors.getById["e_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('e_content').value);
|
|
}
|
|
|
|
if($(ele).attr('name') == 'p_content'){
|
|
oEditors.getById["p_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_content').value);
|
|
}
|
|
if($(ele).attr('name') == 'p_features'){
|
|
oEditors1.getById["p_features"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_features').value);
|
|
}
|
|
if($(ele).attr('name') == 'p_components'){
|
|
oEditors2.getById["p_components"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_components').value);
|
|
}
|
|
if($(ele).attr('name') == 'p_procedure'){
|
|
oEditors3.getById["p_procedure"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_procedure').value);
|
|
}
|
|
if($(ele).attr('name') == 'p_features_list_info'){
|
|
oEditors4.getById["p_features"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_features_list_info').value);
|
|
}
|
|
if($(ele).attr('name') == 'p_components_list_info'){
|
|
oEditors5.getById["p_components"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_components_list_info').value);
|
|
}
|
|
if($(ele).attr('name') == 'p_procedure_list_info'){
|
|
oEditors6.getById["p_procedure"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('p_procedure_list_info').value);
|
|
}
|
|
if($(ele).attr('name') == 'ps_content'){
|
|
oEditors.getById["ps_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('ps_content').value);
|
|
}
|
|
|
|
|
|
if($(ele).val()==''){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 필수 항목입니다';
|
|
}
|
|
else if($(ele).val()=='<br>'){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 필수 항목입니다';
|
|
}
|
|
|
|
}else if ($(ele).attr('type')=='select-multiple'){
|
|
|
|
if($(ele).val()==null){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 필수 항목입니다';
|
|
}
|
|
}else{
|
|
|
|
if($(ele).attr('name') == 'b_content'){
|
|
oEditors.getById["b_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('b_content').value);
|
|
}
|
|
if($(ele).attr('name') == 'e_content'){
|
|
oEditors.getById["e_content"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
$(ele).val(document.getElementById('e_content').value);
|
|
}
|
|
|
|
|
|
if($(ele).val()==''){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 필수 항목입니다';
|
|
}
|
|
}
|
|
},
|
|
|
|
valEqual:function(ele, o){
|
|
if($(ele).val() != $(this.form[o.equal]).val()){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 값이 일치하지 않습니다';
|
|
}
|
|
},
|
|
|
|
valMinlength:function(ele, o){
|
|
if ($(ele).val().length < o.minlength){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 최소 ' + o.minlength + '자 이상 입력하세요.';
|
|
}
|
|
},
|
|
|
|
valEmail:function(ele, o){
|
|
var pattern = /([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/;
|
|
if (!pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 잘못된 이메일로 추정됩니다.';
|
|
}
|
|
},
|
|
|
|
valHangul:function(ele, o){
|
|
var pattern = /[^가-힣]/;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 한글만 입력 가능합니다';
|
|
}
|
|
},
|
|
|
|
valHangul2:function(ele, o){
|
|
var pattern = /[^가-힣ㄱ-ㅎㅏ-ㅣ]/;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 한글만 입력 가능합니다';
|
|
}
|
|
},
|
|
|
|
valMemberid:function(ele, o){
|
|
var pattern = /^[^a-z0-9]|[^a-z0-9_]/;
|
|
if (pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label +
|
|
'] 회원아이디 형식이 아닙니다\n\n' +
|
|
'(알파벳소문자, 숫자, \'_\' 만 가능합니다. 첫글자 영문자,숫자)';
|
|
}
|
|
},
|
|
|
|
valNospace:function(ele, o){
|
|
var pattern = /(\s)/g;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.msg = '[' + o.label + '] 공백문자는 입력할 수 없습니다';
|
|
}
|
|
|
|
},
|
|
|
|
valNumeric:function(ele, o){
|
|
|
|
if(!o.numeric) return;
|
|
|
|
var pattern = /[^0-9]/;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 숫자만 입력할 수 있습니다';
|
|
}
|
|
|
|
// var pattern = /^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/;
|
|
// if(!pattern.test($(ele).val())){
|
|
// this.error.result = true;
|
|
// this.error.type = 'alert';
|
|
// this.error.msg = '[' + o.label + '] 숫자만 입력할 수 있습니다';
|
|
// }
|
|
|
|
},
|
|
|
|
valAlpha:function(ele, o){
|
|
var pattern = /[^a-z]/i;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 영문자만 입력할 수 있습니다';
|
|
}
|
|
},
|
|
|
|
valAlphanumeric:function(ele, o){
|
|
var pattern = /[^a-z0-9]/i;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 영문자와 숫자만 입력할 수 있습니다';
|
|
}
|
|
},
|
|
|
|
valAlphanumeric_:function(ele, o){
|
|
var pattern = /[^a-z0-9_]/i;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 영문자, 숫자, \'-\' 만 입력할 수 있습니다';
|
|
}
|
|
},
|
|
|
|
valPhonenumber:function(ele, o){
|
|
|
|
if(!o.phonenumber) return;
|
|
var pattern = /^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/;
|
|
if(!pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 잘못된 번호 같습니다';
|
|
}
|
|
|
|
// var pattern = /^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/;
|
|
// var pattern = /^[0-9]{10,11}$/;
|
|
// if(!pattern.test($(ele).val())){
|
|
// this.error.result = true;
|
|
// this.error.type = 'alert';
|
|
// this.error.msg = '[' + o.label + '] 잘못된 번호 같습니다';
|
|
// }
|
|
},
|
|
|
|
valHangulalphanumeric:function(ele, o){
|
|
var pattern = /[^가-힣a-z0-9]/i;
|
|
if(pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 한글, 영문, 숫자만 입력할 수 있습니다';
|
|
}
|
|
},
|
|
|
|
// 주민등록번호 검사 (그누보드에 있던거 약간 수정)
|
|
valJumin:function(ele, o){
|
|
var value = $(ele).val().replace(/[^\d]/g, '');
|
|
var pattern = /\d{13}/;
|
|
if (!pattern.test(value)) {
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 주민번호 13자리를 입력해 주세요';
|
|
}else{
|
|
var sum_1 = 0;
|
|
var sum_2 = 0;
|
|
var at=0;
|
|
var juminno = value;
|
|
sum_1 = (juminno.charAt(0)*2)+
|
|
(juminno.charAt(1)*3)+
|
|
(juminno.charAt(2)*4)+
|
|
(juminno.charAt(3)*5)+
|
|
(juminno.charAt(4)*6)+
|
|
(juminno.charAt(5)*7)+
|
|
(juminno.charAt(6)*8)+
|
|
(juminno.charAt(7)*9)+
|
|
(juminno.charAt(8)*2)+
|
|
(juminno.charAt(9)*3)+
|
|
(juminno.charAt(10)*4)+
|
|
(juminno.charAt(11)*5);
|
|
sum_2=sum_1 % 11;
|
|
|
|
if (sum_2 == 0)
|
|
at = 10;
|
|
else
|
|
{
|
|
if (sum_2 == 1) at = 11;
|
|
else at = sum_2;
|
|
}
|
|
att = 11 - at;
|
|
if (juminno.charAt(12) != att ||
|
|
juminno.substr(2,2) < '01' ||
|
|
juminno.substr(2,2) > '12' ||
|
|
juminno.substr(4,2) < '01' ||
|
|
juminno.substr(4,2) > '31' ||
|
|
juminno.charAt(6) > 4){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 올바른 주민등록번호가 아닙니다';
|
|
}
|
|
}
|
|
},
|
|
|
|
//긁어 왔는데 누구님껀지 기억이 안남 ㅜㅜ
|
|
valTaxno:function(ele, o){
|
|
var value = $(ele).val().replace(/[^\d]/g, '');
|
|
var sum = 0;
|
|
var getlist = new Array(10);
|
|
var chkvalue = new Array('1','3','7','1','3','7','1','3','5');
|
|
for(var i=0; i<10; i++) { getlist[i] = value.substring(i, i+1); }
|
|
for(var i=0; i<9; i++) { sum += getlist[i]*chkvalue[i]; }
|
|
sum = sum + parseInt((getlist[8]*5)/10);
|
|
sidliy = sum % 10;
|
|
sidchk = 0;
|
|
if(sidliy != 0) { sidchk = 10 - sidliy; }
|
|
else { sidchk = 0; }
|
|
if(sidchk != getlist[9]){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 잘못된 사업자등록번호입니다';
|
|
}
|
|
},
|
|
|
|
valGroupcheck:function(ele, o){
|
|
var flag = false;
|
|
ele = document.getElementsByName(ele.name);
|
|
for(i=0;i<ele.length;i++) if(ele[i].checked) flag = true;
|
|
|
|
if(!flag){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 최소한 하나이상 체크하셔야 합니다';
|
|
}
|
|
},
|
|
|
|
valZipcode:function(ele, o){
|
|
var pattern = /^\d{3}-?\d{3}($)/;
|
|
if(!pattern.test($(ele).val())){
|
|
this.error.result = true;
|
|
this.error.type = 'alert';
|
|
this.error.msg = '[' + o.label + '] 우편번호가 잘못된것 같습니다';
|
|
}
|
|
},
|
|
|
|
valUniq:function(ele, o){
|
|
var validator = this;
|
|
var data = {};
|
|
data[$(ele).attr('name')] = encodeURIComponent($(ele).val());
|
|
o.uniq = o.uniq;
|
|
$.ajax({type:'post', async:false, url:o.uniq, data:data, success:function(data){
|
|
if(data=='false'){
|
|
validator.error.result = true;
|
|
validator.error.type = 'alert';
|
|
validator.error.msg = '이미 사용중입니다';
|
|
}
|
|
}});
|
|
}
|
|
},
|
|
|
|
//===========================================================================
|
|
// Static 메쏘드
|
|
//===========================================================================
|
|
setResult:function(){
|
|
var obj = {};
|
|
obj.result = true;
|
|
obj.msg = msg;
|
|
},
|
|
|
|
bothTrim:function(value){
|
|
var pattern = /(^\s*)|(\s*$)/g;
|
|
return value.replace(pattern, '');
|
|
},
|
|
|
|
ucfirst:function(value){
|
|
str = value.toString();
|
|
var x = str.split(/\s+/g);
|
|
for (var i = 0; i < x.length; i++) {
|
|
var parts = x[i].match(/(\w)(\w*)/);
|
|
x[i] = parts[1].toUpperCase() + parts[2].toLowerCase();
|
|
}
|
|
return x.join(' ');
|
|
}
|
|
});
|
|
|
|
$.extend({
|
|
validate:function(){
|
|
v = new $.validator();
|
|
|
|
$(document.forms).each(function(){
|
|
ref = this;
|
|
$(this).submit(function(){
|
|
|
|
oEditors.getById["description"].exec("UPDATE_CONTENTS_FIELD", []);
|
|
//return v.validCheck(ref);
|
|
|
|
returnData = v.validCheck(ref);
|
|
|
|
if(returnData!=false)
|
|
{
|
|
if (fileUpload_bool)
|
|
{
|
|
return fileUploadCheck();
|
|
}else
|
|
{
|
|
return returnData;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
});
|
|
});
|
|
}
|
|
});
|
|
})(jQuery);
|
|
|
|
var fileUpload_bool = false;
|
|
$(function(){
|
|
$.validate();
|
|
|
|
|
|
try
|
|
{
|
|
if(fileUploadCheck) {
|
|
|
|
}
|
|
fileUpload_bool=true;
|
|
} catch(e) {
|
|
fileUpload_bool=false;
|
|
}
|
|
});
|
|
//-->
|