$('#frmContent').validate({
debug: false,
onfocusout: false,
rules: {
RegistType: { required: true },
collectiveJibun: {
required: function (element) {
var jibun = $("#collectiveJibun").val();
return $("#collectiveJibunCheck").is(":checked") && jibun != null ? true : false;
},
jibunCheck : true -- custom method
}
}, messages: {
RegistType: { required: '구분을 선택하세요.' },
collectiveJibun: { required: '지번을 입력하세요.', jibunCheck: '지번형식에 맞지 않습니다.' },
}, errorPlacement: function (error, element) {
// do nothing
}, invalidHandler: function (form, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
alert(validator.errorList[0].message);
validator.errorList[0].element.focus();
}
}, submitHandler: function (form) {
if (confirm("입력된 내용으로 저장하시겠습니까?")) {
var formCollection = $(form).serialize();
$.post("/RegistrationAlarm/RegAlarmProc", formCollection,
function (data, textStatus, jqXHR) {
if (data.result == "success") {
alert("입력된 내용이 저장되었습니다.");
window.location.href = "/RegistrationAlarm/RegAlarmList";
}
else {
alert("저장 시 오류가 발생하였습니다.");
}
}
);
return false;
}
}
});
$.validator.addMethod("jibunCheck", function (value, element) {
return this.optional(element) || /(^[0-9]{1,4}-[0-9]{1,4}$)|(^[0-9]{1,4}$)/.test(value);
});