/* ----------------------------------------------------------------------------------------------------
설명 : 폼 체크 유효성 검사하는 통합 자바스크립트 함수
작성폰트 : Verdana/ Regular/ 8
작성일 : 2011.10
작성자 : 박세민 pseeq@naver.com
---------------------------------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------------------
정규패턴식 변수정의
---------------------------------------------------------------------------------------------------- */
var OnlyNumber = /^[0-9]+$/
var OnlyEnglish = /^[a-z|A-Z]+$/
var OnlyKorea = /^[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]+$/
var EmailCheck1 = /^([a-z]([a-z|0-9|_|-]{3,19})@([a-z|A-Z|0-9]{2,20})\.([a-z|A-Z]{2,5}))+$/
var EmailCheck2 = /^([a-z]([a-z|0-9|_|-]{3,19})@([a-z|A-Z|0-9]{2,20})\.([a-z|A-Z]{2,10})\.([a-z|A-Z]{2,5}))+$/
var IdCheck = /^([a-z]([a-z|0-9|_|-]{3,19}))+$/
var NicNameCheck =/^([가-힣a-zA-Z0-9_-~`!@#$^&*=+]{2,20})+$/
var EmailAfterCheck1 = /^(([a-z|0-9]{2,20})\.([a-z|A-Z]{2,10})\.([a-z|A-Z]{2,5}))+$/
var EmailAfterCheck2 = /^(([a-z|0-9]{2,20})\.([a-z|A-Z]{2,5}))+$/
var InjectionCheck = /\/\*|\*\/|%|@variable|xp_cmdshell|xp_stratmail|xp_sendmail|xp_grantlogin|xp_makewebtask|xp_dirtree|db_owner|xp_|sp_|db_|union|sysobjects|is_srvrolemember|cookie|shutdown|alter|\.js|script|create|declare|select|insert|drop|update|delete|truncate|cmdshell|execmaster|exec|netlocalgroupadministratthens|netuser|kill|xmp|count\(|asc\(|mid\(|char\(|varchar\(|db_name\(\)|openrowset\(\)/
// 파일 확장자 검사 변수
var NicTypeMsg = "_-~`!@#$^&*=+";
var ImageTypeMsg = "gif, jpg, jpeg, png";
var ImageType = /\.(gif|jpg|jpeg|png)$/
var MovieTypeMsg = "wmv, asf";
var MovieType = /\.(wmv|asf)$/
var WordTypeMsg = "ppt, xls, csv, hwp, doc, txt";
var WordType = /\.(ppt|xls|csv|hwp|doc|txt)$/
var ComTypeMsg = "alz, zip";
var ComType = /\.(alz|zip)$/
var SwfTypeMsg = "swf";
var SwfType = /\.(swf)$/
var InSTypeMsg = "gif, jpg, jpeg, png, swf";
var InSType = /\.(gif|jpg|jpeg|png|swf)$/
// 주민번호 앞자리 저장 변수
var Jumin_Front_Object = "";
// 비교 객체1 저장 변수
var Tp_Front_Object = "";
/* ----------------------------------------------------------------------------------------------------
작성목적 : 객체가 있는지 검사
Parameter :
obj - 검사할 객체
---------------------------------------------------------------------------------------------------- */
function ObjectYN(obj)
{
if (typeof(obj) != "undefined" && obj != "" && obj != null) {
return true;
} else {
return false;
}
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 객체가 있는지 검사 - 어트리뷰트 전용
Parameter :
obj - 검사할 객체
---------------------------------------------------------------------------------------------------- */
function AttYN(obj)
{
if (typeof(obj) != "undefined" && obj != null) {
return true;
} else {
return false;
}
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 앞, 뒤 공백 제거
Parameter :
Field - 객체 값
---------------------------------------------------------------------------------------------------- */
function strTrim(Field)
{
Field = Field.replace(/(^\s*)|(\s*$)/g, "")
// Field = Field.replace("
", "")
return Field;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 객체속성 체크함수
Parameter :
CheckElement - 해당객체
Return :
Element - 객체
TypeName - 객체타입
TagName - 객체태그
ElementName - 객체이름
ElementValue - 객체값
---------------------------------------------------------------------------------------------------- */
function ElementPrototype(CheckElement)
{
// 라디오박스/체크박스 = true
if (CheckElement.length > 1 && ObjectYN(CheckElement.options) == false)
{
return {
Element : CheckElement[0],
TypeName : CheckElement[0].type.toUpperCase(),
TagName : CheckElement[0].tagName.toUpperCase(),
ElementName : CheckElement[0].name,
ElementValue : CheckElement[0].value
}
}
else
{
return {
Element : CheckElement,
TypeName : CheckElement.type.toUpperCase(),
TagName : CheckElement.tagName.toUpperCase(),
ElementName : CheckElement.name,
ElementValue : CheckElement.value
}
}
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 폼안의 어트리뷰트 체크함수
Parameter :
CheckElement - 해당객체
---------------------------------------------------------------------------------------------------- */
function ElementAttribute(CheckElement)
{
// 경고창에 표시될 객체명
if (ObjectYN(CheckElement.getAttribute("title")) == true) {
AL_Title = CheckElement.getAttribute("title");
} else {
AL_Title = "";
}
return {
AL_Title : AL_Title, // 객체명
// 유효성 체크
AL_Exp : CheckElement.getAttribute("exp"), // 필수입력
AL_Num : CheckElement.getAttribute("num"), // 숫자만입력
AL_Eng : CheckElement.getAttribute("eng"), // 영어만입력
AL_Kor : CheckElement.getAttribute("kor"), // 한글만입력
AL_Uid : CheckElement.getAttribute("uid"), // ID형식 체크
AL_Nic : CheckElement.getAttribute("nic"), // 닉네임형식 체크
AL_Inj : CheckElement.getAttribute("inj"), // 인젝션공격성 문자열 체크
// 이메일 체크
AL_Eml : CheckElement.getAttribute("eml"), // E-mail 형식 체크
AL_Ela : CheckElement.getAttribute("ela"), // E-mail 뒷부분 형식 체크
// 파일유효성 체크
AL_Img : CheckElement.getAttribute("img"), // 이미지만 업로드
AL_Mov : CheckElement.getAttribute("mov"), // 영상만 업로드
AL_Wor : CheckElement.getAttribute("wor"), // 문서만 업로드
AL_Com : CheckElement.getAttribute("com"), // 압축파일만 업로드
AL_Swf : CheckElement.getAttribute("swf"), // 플래시파일만 업로드
AL_Ins : CheckElement.getAttribute("ins"), // 이미지/플래시파일만 업로드
// 에디터 체크
AL_Fckexp : CheckElement.getAttribute("fckexp"), // FCK 에디터 필수입력
AL_Fckinj : CheckElement.getAttribute("fckinj"), // FCK 에디터 필수입력
AL_Easyexp : CheckElement.getAttribute("easyexp"), // 이지웹 에디터 필수입력
AL_Easyinj : CheckElement.getAttribute("easyinj"), // 이지웹 에디터 인젝션공격성 문자열 체크
// 주민등록번호 체크
AL_Ju1 : CheckElement.getAttribute("ju1"), // 주민등록번호 앞자리 체크
AL_Ju2 : CheckElement.getAttribute("ju2"), // 주민등록번호 뒷자리 체크
AL_Jum : CheckElement.getAttribute("jum"), // 주빈등록번호 체크
// 비교 체크
AL_Tp1 : CheckElement.getAttribute("tp1"), // 비교 객체1 저장
AL_Tp2 : CheckElement.getAttribute("tp2") // 비교 객체1, 2 체크
}
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 폼안의 객체검사
Parameter :
form - 검사할 폼
사용법 :
if(FormCheck(폼 객체) == true)
{
frm.action = "액션페이지";
frm.submit();
}
---------------------------------------------------------------------------------------------------- */
function FormCheck(form)
{
var obj, att, f;
var ElementLength = form.elements.length;
for (f=0; f " || strTrim(obj.ElementValue) == " ")
{
if (obj.TypeName == "HIDDEN") {
alert("["+ AlertMsg +"] 값이 없습니다.\n\n관리자에게 문의해주세요.");
return false;
} else {
alert("["+ AlertMsg +"] 필수입력사항");
obj.Element.focus();
return false;
}
}
}
else if (obj.TypeName == "FILE")
{
if (strTrim(obj.ElementValue) == "")
{
alert("["+ AlertMsg +"] 필수등록사항");
obj.Element.focus();
return false;
}
}
else if (obj.TypeName == "SELECT-ONE")
{
if (strTrim(obj.ElementValue) == "")
{
alert("["+ AlertMsg +"] 필수선택사항");
obj.Element.focus();
return false;
}
}
else if (obj.TypeName == "RADIO")
{
var Radio_YN = "N";
var RadioName = document.getElementsByName(obj.ElementName);
if (ObjectYN(RadioName.length) == true)
{
for (r=0; r " || strTrim(obj_ElementValue) == " " || strTrim(obj_ElementValue) == "" || strTrim(obj_ElementValue) == "
" || strTrim(obj_ElementValue) == "
")
{
alert("["+ AlertMsg +"] 필수입력사항");
// obj.EditorDocument.body.focus();
obj.Focus();
return false;
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : FCK 에디터 인젝션 체크함수
Parameter :
CheckElement - 해당객체/ 에디터 객체이름
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Fckinj(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = FCKeditorAPI.GetInstance(CheckElement);
// 에디터 객체값 다시 정의
// var obj_ElementValue = obj.EditorDocument.body.innerHTML.toLowerCase();
var obj_ElementValue = obj.GetXHTML().toLowerCase();
// 폼검사
if (strTrim(obj_ElementValue) == "" || strTrim(obj_ElementValue) == "
" || strTrim(obj_ElementValue) == " " || strTrim(obj_ElementValue) == "" || strTrim(obj_ElementValue) == "
" || strTrim(obj_ElementValue) == "
") { }
else
{
if (InjectionCheck.test(obj_ElementValue.toLowerCase()) == true)
{
alert("["+ AlertMsg +"] 형식에\n["+ obj_ElementValue.toLowerCase().match(InjectionCheck) +"]\n문자는 입력할수없습니다.");
obj.Focus();
return false;
}
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 이지웹 에디터 체크함수
Parameter :
CheckElement - 해당객체/ 에디터 객체이름
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Easyexp(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 에디터 객체값 다시 정의
obj.ElementValue = eval(obj.ElementName +".getHtml()");
// 폼검사
if (strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == " " || strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == "
")
{
alert("["+ AlertMsg +"] 필수입력사항");
// obj.Element.focus();
return false;
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 이지웹 에디터 인젝션 체크함수
Parameter :
CheckElement - 해당객체/ 에디터 객체이름
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Easyinj(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 에디터 객체값 다시 정의
obj.ElementValue = eval(obj.ElementName +".getHtml()");
// 폼검사
if (strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == " " || strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == "
") { }
else
{
if (InjectionCheck.test(obj.ElementValue.toLowerCase()) == true)
{
alert("["+ AlertMsg +"] 형식에\n["+ obj.ElementValue.toLowerCase().match(InjectionCheck) +"]\n문자는 입력할수없습니다.");
// obj.Element.value = obj.ElementValue.replace(obj.ElementValue.match(InjectionCheck), "");
// obj.Element.focus();
return false;
}
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : tinyMCE 에디터 체크함수
Parameter :
CheckElement - 해당객체/ 에디터 객체이름
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Tinyexp(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 에디터 객체값 다시 정의
obj.ElementValue = eval(obj.ElementName +".getHtml()");
// 폼검사
if (strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == " " || strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == "
")
{
alert("["+ AlertMsg +"] 필수입력사항");
// obj.Element.focus();
return false;
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : tinyMCE 에디터 인젝션 체크함수
Parameter :
CheckElement - 해당객체/ 에디터 객체이름
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Tinyinj(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 에디터 객체값 다시 정의
obj.ElementValue = eval(obj.ElementName +".getHtml()");
// 폼검사
if (strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == " " || strTrim(obj.ElementValue) == "" || strTrim(obj.ElementValue) == "
" || strTrim(obj.ElementValue) == "
") { }
else
{
if (InjectionCheck.test(obj.ElementValue.toLowerCase()) == true)
{
alert("["+ AlertMsg +"] 형식에\n["+ obj.ElementValue.toLowerCase().match(InjectionCheck) +"]\n문자는 입력할수없습니다.");
// obj.Element.value = obj.ElementValue.replace(obj.ElementValue.match(InjectionCheck), "");
// obj.Element.focus();
return false;
}
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 주민등록번호 앞자리 체크함수
Parameter :
CheckElement - 해당객체
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Ju1(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 폼검사
if (strTrim(obj.ElementValue) != "")
{
if (obj.TypeName == "TEXT" || obj.TypeName == "PASSWORD" || obj.TypeName == "TEXTAREA" || obj.TypeName == "HIDDEN")
{
if(FormCheckSub(CheckElement, "num", AlertMsg) == false) {
return false;
}
if (strTrim(obj.ElementValue).length != 6)
{
alert("["+ AlertMsg +"] 형식이 올바르지않습니다.");
obj.Element.value = "";
obj.Element.focus();
return false;
}
}
}
// 주민등록번호 앞자리 저장
Jumin_Front_Object = obj;
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 주민등록번호 뒷자리 체크함수
Parameter :
CheckElement - 해당객체
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Ju2(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 폼검사
if (strTrim(obj.ElementValue) != "")
{
if (obj.TypeName == "TEXT" || obj.TypeName == "PASSWORD" || obj.TypeName == "TEXTAREA" || obj.TypeName == "HIDDEN")
{
if(FormCheckSub(CheckElement, "num", AlertMsg) == false) {
return false;
}
if (strTrim(obj.ElementValue).length != 7)
{
alert("["+ AlertMsg +"] 형식이 올바르지않습니다.");
obj.Element.value = "";
obj.Element.focus();
return false;
}
if (strTrim(Jumin_Front_Object.ElementValue) != "" && strTrim(obj.ElementValue) != "")
{
if (JuminNumberCheck(Jumin_Front_Object.ElementValue, obj.ElementValue) == true)
{
alert("["+ AlertMsg +"] 형식이 올바르지않습니다.");
Jumin_Front_Object.Element.value = "";
obj.Element.value = "";
Jumin_Front_Object.Element.focus();
return false;
}
}
}
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 주민등록번호 전체 체크함수
Parameter :
CheckElement - 해당객체
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Jum(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 폼검사
if (strTrim(obj.ElementValue) != "")
{
if (obj.TypeName == "TEXT" || obj.TypeName == "PASSWORD" || obj.TypeName == "TEXTAREA" || obj.TypeName == "HIDDEN")
{
if(FormCheckSub(CheckElement, "num", AlertMsg) == false) {
return false;
}
if (strTrim(obj.ElementValue).length != 13)
{
alert("["+ AlertMsg +"] 형식이 올바르지않습니다.");
obj.Element.value = "";
obj.Element.focus();
return false;
}
if (JuminNumberCheck(obj.ElementValue.substring(0, 6), obj.ElementValue.substring(6, 13)) == true)
{
alert("["+ AlertMsg +"] 형식이 올바르지않습니다.");
obj.Element.value = "";
obj.Element.focus();
return false;
}
}
}
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 주민등록번호 유효성 검사
Parameter :
strJumin1 - 주민등록번호 앞자리
strJumin2 - 주민등록번호 뒷자리
---------------------------------------------------------------------------------------------------- */
function JuminNumberCheck(strJumin1, strJumin2)
{
var JuminNumber = strJumin1 + strJumin2;
var ju = new Array(13);
for (var i=0; i<13; i++) {
ju[i] = parseInt(JuminNumber.charAt(i));
}
var jn = ju[0]*2 + ju[1]*3 + ju[2]*4 + ju[3]*5 + ju[4]*6 + ju[5]*7 + ju[6]*8 + ju[7]*9 + ju[8]*2 + ju[9]*3 + ju[10]*4 + ju[11]*5;
var jn = jn % 11;
var re = 11 - jn;
if(re > 9) { re = re % 10; }
if(re != ju[12])
{ return true; } //올바르지 않은 번호
else
{ return false; } //올바른 번호
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 비교 객체1 저장
Parameter :
CheckElement - 해당객체
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Tp1(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 폼검사
if(FormCheckSub(CheckElement, "exp", AlertMsg) == false) {
return false;
}
// 객체1 저장
Tp_Front_Object = obj;
return true;
}
/* ----------------------------------------------------------------------------------------------------
작성목적 : 비교 객체1, 2 체크
Parameter :
CheckElement - 해당객체
AlertMsg - 경고창 내용
---------------------------------------------------------------------------------------------------- */
function Fn_Tp2(CheckElement, AlertMsg)
{
// 객체속성 체크함수
var obj = ElementPrototype(CheckElement);
// 폼검사
if(FormCheckSub(CheckElement, "exp", AlertMsg) == false) {
return false;
}
if (strTrim(Tp_Front_Object.ElementValue) != "" && strTrim(obj.ElementValue) != "")
{
if (Tp_Front_Object.ElementValue != obj.ElementValue)
{
alert("["+ AlertMsg +"] 서로 일치하지않습니다.");
Tp_Front_Object.Element.value = "";
obj.Element.value = "";
Tp_Front_Object.Element.focus();
return false;
}
}
return true;
}
function isAlphaNum(str)
{
var flag1=flag2=false;
var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var num = "1234567890";
var minlen = 6;
var len = str.length;
var ch,flag1,flag2;
for(i = 0 ; i < len ; i++ ){
ch=str.charAt(i);
if(alpha.match(ch)){
flag1 = true;
break;
}
}
for(i = 0 ; i < len ; i++ ){
ch=str.charAt(i);
if(num.match(ch)){
flag2 = true;
break;
}
}
if (len < minlen){
flag1 = false;
flag2 = false;
}
return ( flag1 && flag2 ) ? true : false;
}