작성일 댓글 남기기

유연한 자동 폼 검사기

function chkForm(f)
{
var i,currEl;

for(i = 0; i < f.elements.length; i++){
currEl = f.elements[i];
//필수 항목을 체크한다.
if (currEl.getAttribute("required") != null) {
if(currEl.type == "TEXT" || currEl.type == "text" ||
currEl.tagName == "SELECT" || currEl.tagName == "select" ||
currEl.tagName == "TEXTAREA" || currEl.tagName == "textarea"){
if(!chkText(currEl,currEl.hname)) return false;

} else if(currEl.type == "PASSWORD" || currEl.type == "password"){
if(!chkText(currEl,currEl.hname)) return false;

} else if(currEl.type == "CHECKBOX" || currEl.type == "checkbox"){
if(!chkCheckbox(f, currEl,currEl.hname)) return false;

} else if(currEl.type == "RADIO" || currEl.type == "radio"){
if(!chkRadio(f, currEl,currEl.hname)) return false;

}
}
// 입력 페턴을 체크한다.
if(currEl.getAttribute("option") != null && currEl.value.length > 0){
if(!chkPatten(currEl,currEl.option,currEl.hname)) return false;
}
}
}

function chkPatten(field,patten,name)
{
var regNum =/^[0-9]+$/;
var regPhone =/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/;
var regMail =/^[_a-zA-Z0-9-]+@[._a-zA-Z0-9-]+.[a-zA-Z]+$/;
var regDomain =/^[.a-zA-Z0-9-]+.[a-zA-Z]+$/;
var regAlpha =/^[a-zA-Z]+$/;
var regHost =/^[a-zA-Z-]+$/;
var regHangul =/[가-