var common = {
datepicker : function(){
$(“.datepicker”).datepicker({
dateFormat : ‘yy-mm-dd’
, prevText : ‘이전달’
, nextText : ‘다음달’
, monthNames : [‘1월’,’2월’,’3월’,’4월’,’5월’,’6월’,’7월’,’8월’,’9월’,’10월’,’11월’,’12월’]
, monthNamesShort : [‘1월’,’2월’,’3월’,’4월’,’5월’,’6월’,’7월’,’8월’,’9월’,’10월’,’11월’,’12월’]
, dayNamesMin : [‘일’,’월’,’화’,’수’,’목’,’금’,’토’]
, showMonthAfterYear : true
, inline : true
, changeMonth : true
, changeYear : true
, showMonthAfterYear : true
, showButtonPanel : true // 캘린더 하단에 버튼 패널을 표시한다.
, currentText : ‘오늘 날짜’ // 오늘 날짜로 이동하는 버튼 패널
, closeText : ‘닫기’
});
$(“.datepicker”).mask(“9999-99-99”);
$(“.datepicker”).blur(function(){
if(!validation.isNull($(this).val()) && !validation.isValidDate($(this).val())){
$(this).val(“”);
$(this).focus();
alert(“올바르지 않은 날짜입니다.”);
}
});
$(“.datepickerBtn”).click(function(){
$(this).prev().focus();
});
}
, numeric : function(){
$(“.numeric”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.numeric”).mask(“#0”, {reverse: true, maxlength: false});
}
, decimal : function(){
$(“.decimal”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.decimal”).autoNumeric(“init”,{
aSep: ‘,’
, aDec: ‘.’
, vMax : ‘9999999999999.9’
, vMin : ‘-9999999999999.9’
});
}
, decimalNoPoint : function(){
$(“.decimalNoPoint”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.decimalNoPoint”).autoNumeric(“init”,{
aSep: ‘,’
, aDec: ‘.’
, vMax : ‘9999999999999’
, vMin : ‘-9999999999999’
});
}
, decimalExceptSep : function(){
$(“.decimal”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.decimal”).autoNumeric(“init”,{
aSep: ”
, aDec: ‘.’
, vMax : ‘9999999999999.9’
, vMin : ‘-9999999999999.9’
});
}
, phoneNumber : function() {
var phoneMask = function (val) {
var mask = “000-000-000000”;
var value = val.replace(/\D/g, ”);
if(value.length > 2) {
if(value.substring(0,2) == “02”){
mask = “00-000-00000”
if(value.length == 10) {
mask = “00-0000-0000”
}
} else if(value.substring(0,2) == “01”){
if(value.length == 11) {
mask = “000-0000-0000”
}
} else {
if(value.length == 11) {
mask = “000-0000-0000”
} else if(value.length == 12) {
mask = “0000-0000-0000”
}
}
}
return mask;
}
var option = {
onKeyPress: function(val, e, field, options) {
field.mask(phoneMask.apply({}, arguments), options);
}
, onComplete: function(val, e, field, options) {
var mask = “000-000-000000”;
var value = val.replace(/\D/g, ”);
if(value.length > 2) {
if(value.substring(0,2) == “02”){
mask = “00-000-00000”
if(value.length == 10) {
mask = “00-0000-0000”
}
} else if(value.substring(0,2) == “01”){
if(value.length == 11) {
mask = “000-0000-0000”
}
} else {
if(value.length == 11) {
mask = “000-0000-00000”
} else if(value.length == 12) {
mask = “0000-0000-0000”
}
}
}
field.mask(mask, options);
}
}
$(‘.phoneNumber’).mask(phoneMask, option);
}
, comma : function() {
if ($(‘.comma’).val() != undefined) {
$(“.comma”).each(function() {
$(‘#’ + $(this).attr(“id”)).val($(‘#’ + $(this).attr(“id”)).val().replace(/([^0-9\,])/g, ”));
});
}
$(‘.comma’).mask(“#,##0”, {reverse: true, maxlength: false});
}
, numberOnly : function() {
if ($(‘.numberOnly’).val() != undefined) {
$(“.numberOnly”).each(function() {
$(‘#’ + $(this).attr(“id”)).val($(‘#’ + $(this).attr(“id”)).val().replace(/([^0-9\,])/g, ”));
});
$(“.numberOnly”).mask(“#0”, {reverse: true, maxlength: false});
}
}
, rateOnly : function() {
$(“.rateOnly”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.rateOnly”).autoNumeric(“init”,{
aSep: ‘,’
, aDec: ‘.’
, vMax : ‘99.99’
, vMin : ‘0.00’
});
}
, rateOnly2 : function() {
$(“.rateOnly2”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.rateOnly2”).autoNumeric(“init”,{
aSep: ‘,’
, aDec: ‘.’
, vMax : ‘100’
, vMin : ‘0.00’
});
}
, bigRateOnly : function() {
$(“.rateOnly”).css(“ime-mode”, “disabled”);//한글입력 X
$(“.rateOnly”).autoNumeric(“init”,{
aSep: ‘,’
, aDec: ‘.’
, vMax : ‘9999.99’
, vMin : ‘0.00’
});
}
, onlyKorNum : function() {
if ($(‘.onlyKorNum’).val() != undefined) {
$(“.onlyKorNum”).each(function() {
$(‘#’ + $(this).attr(“id”)).on(‘paste drop change blur focusout DOMNodeInserted’, function(){
$(‘#’ + $(this).attr(“id”)).val($(‘#’ + $(this).attr(“id”)).val().replace(/([^ㄱ-ㅎ|ㅏ-ㅣ|가-힣0-9])/g, ”));
});
});
}
}
, onlyEng : function() {
if ($(‘.onlyEng’).val() != undefined) {
$(“.onlyEng”).each(function() {
$(‘#’ + $(this).attr(“id”)).on(‘paste drop change blur focusout DOMNodeInserted’, function(){
$(‘#’ + $(this).attr(“id”)).val($(‘#’ + $(this).attr(“id”)).val().replace(/([^a-zA-Z])/g, ”));
});
});
}
}
, onlyEngNum : function() {
if ($(‘.onlyEngNum’).val() != undefined) {
$(“.onlyEngNum”).each(function() {
$(‘#’ + $(this).attr(“id”)).on(‘paste drop change blur focusout DOMNodeInserted’, function(){
$(‘#’ + $(this).attr(“id”)).val($(‘#’ + $(this).attr(“id”)).val().replace(/([^a-zA-Z0-9])/g, ”));
});
});
}
}
, readOnly : function() {
// IE에서 readonly 속성 input 백스페이스 키 입력 시 브라우저 back 처리됨을 막음
//한번 적용된 이벤트 삭제되지 않는 문제로 변경
$(document).on(“keydown”, “.readonly”, function(event) {
if (event.keyCode == 8) {
return false;
}
});
}
, forbidden : function() {
if ($(‘.forbidden’).val() != undefined) {
$(“.forbidden”).each(function() {
$(‘#’ + $(this).attr(“id”)).on(‘change’, function(e){
});
});
}
}
, goodsTitle: function() {
if ($(‘.goodsTitle’).val() != undefined) {
$(‘.goodsTitle’).each(function() {
$(‘#’ + $(this).attr(“id”)).on(‘paste drop change blur focusout DOMNodeInserted’, function(e){
$(‘#’ + $(this).attr(“id”)).val($(‘#’ + $(this).attr(“id”)).val().replace(/[\’\”<,>]/g, ”).replace(‘ ’, ”).replace(‘’, ”));
});
});
}
}
, all : function() {
common.datepicker();
common.numeric();
common.phoneNumber();
common.comma();
common.decimal();
common.decimalNoPoint();
common.numberOnly();
common.rateOnly();
common.rateOnly2();
common.onlyKorNum();
common.onlyEngNum();
common.onlyEng();
common.readOnly();
common.goodsTitle();
common.forbidden();
}
}