$(function() { $(".login").click(function (e) { e.preventDefault(); $('#my_popup').load('/ajax/pop_login.do').popup('show'); }); $(".popup").click(function (e) { e.preventDefault(); $('#my_popup').load($(this).attr('href')).popup('show'); }); }); $.extend($.fn, { validate: function() { var result = true; var obj = this.find('[required],[number],[eng_number],[minlength],[maxlength],[duplicate],[equalTo],[ssnCheck][email1][email2]'); // var obj = this.find('[ccc]'); obj.each(function() { var value = $(this).val(); var title = $(this).attr("title"); if ($(this).is('[required]')) { if ($(this).attr('type') == "radio") { if ($(':radio[name="'+$(this).attr("name")+'"]:checked').length == 0) { alert(title + "을(를) 선택해 주십시오."); $(this).focus(); result = false; return false; } } else if ($(this).attr('type') == "checkbox") { var tmp = $(this).is(':checked'); if (!tmp) { alert(title + "을(를) 선택해 주십시오."); $(this).focus(); result = false; return false; } } else { if (value.length == 0) { if ($(this).get(0).tagName == "SELECT") { alert(title + "을(를) 선택해 주십시오."); } else { alert(title + "을(를) 입력해 주십시오."); } $(this).focus(); result = false; return false; } } } if ($(this).is('[minlength]') && value.length > 0) { var minlength = parseInt($(this).attr('minlength'),10); if (value.length < minlength) { alert(title + "은(는) "+minlength+"자 이상 입력해 주십시오."); $(this).focus(); result = false; return false; } } if ($(this).is('[maxlength]')) { var maxlength = parseInt($(this).attr('maxlength'),10); if (value.length > maxlength) { alert(title + "은(는) "+maxlength+"자 이하 입력해 주십시오."); $(this).focus(); result = false; return false; } } if ($(this).is('[eng_number]') && value.length > 0) { if (!(/^[a-zA-Z-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$]+$/.test(value))) { alert(title + "은(는) 영문/숫자만 입력가능합니다."); $(this).focus(); result = false; return false; } } if ($(this).is('[email1]') && value.length > 0) { if (!/^[0-9a-zA-Z]([\-.\w]*[0-9a-zA-Z\-_+])*$/.test(value)) { alert(title + "은(는) 영문/숫자/특수문자(-._)만 입력가능합니다."); $(this).focus(); result = false; return false; } } if ($(this).is('[email2]') && value.length > 0) { if (!/^((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/.test(value)) { alert(title + "은(는) 영문/숫자만 입력가능합니다."); $(this).focus(); result = false; return false; } } if ($(this).is('[number]') && value.length > 0) { if (!(/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value))) { alert(title + "은(는) 숫자만 입력가능합니다."); $(this).focus(); result = false; return false; } } if ($(this).is('[duplicate]')) { var duplicate = $("#"+$(this).attr('duplicate')).val(); if (duplicate == '') { alert(title + "을(를) 중복체크해 주십시오."); $(this).focus(); result = false; return false; } } if ($(this).is('[equalTo]')) { var equalTo = $("#"+$(this).attr('equalTo')).val(); if (value != equalTo) { alert(title + "가 일치하지 않습니다."); $(this).focus(); result = false; return false; } } if ($(this).is('[ssnCheck]')) { var ssn = $("#"+$(this).attr('ssnCheck')).val(); if (!ssn_check(ssn+value)) { alert("주민등록번호를 바르게 입력 하십시오."); $(this).focus(); result = false; return false; } } }); return result; } }); function ssn_check(value) { var result = true; value = value.replace("-", ""); if (/[^0-9-]+/.test(value)) result = false; var ssnCheck = 0; for (var i = 0; i < 12; i++) { ssnCheck += (i % 8 + 2) * value.charAt(i); } ssnCheck = (11 - ssnCheck % 11) % 10; if(ssnCheck != value.charAt(12)) { result = false; } return result; }