한 걸음씩..

jqGrid ip 본문

프로그래밍

jqGrid ip

smdy0426 2024. 5. 22. 17:22
반응형
var colModel = [
    { index:'IP', name: 'IP', label: 'IP', width: 150, align:'left', editable:true, edittype:"custom",
        editoptions: {
            custom_element: function (value, options) {
                var parts = value.split('.');
                var elemStr = '<div><input id="ip1" size="15" maxlength="3" value="' + (parts[0] ? parts[0] : '0') + '" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\\..*)\\./g, \'$1\');" />' +
                    ' . <input id="ip2" size="15" maxlength="3" value="' + (parts[1] ? parts[1] : '0') + '" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\\..*)\\./g, \'$1\');" />' +
                    ' . <input id="ip3" size="15" maxlength="3" value="' + (parts[2] ? parts[2] : '0') + '" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\\..*)\\./g, \'$1\');" />' +
                    ' . <input id="ip4" size="15" maxlength="3" value="' + (parts[3] ? parts[3] : '0') + '" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\\..*)\\./g, \'$1\');" /></div>';
                return $(elemStr)[0];
            },
            custom_value: function (elem) {
                var inputs = $("input", $(elem)[0]);
                return (inputs[0].value ? inputs[0].value : '0') + '.' + (inputs[1].value ? inputs[1].value : '0') +
                    '.' + (inputs[2].value ? inputs[2].value : '0') + '.' + (inputs[3].value ? inputs[3].value : '0');
            }
        }
    }
];
var data = $("#jqGrid").jqGrid("getRowData");

for( i in data ){
    //IPv4 검사
    if( data[i].IP.match("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$") ){
        continue;
    }

    //IPv4 CIDR 검사
    if( data[i].IP.match("^(([0-9])|([1-9][0-9])|(1([0-9]{2}))|(2[0-4][0-9])|(25[0-5]))((\\.(([0-9])|([1-9][0-9])|(1([0-9]{2}))|(2[0-4][0-9])|(25[0-5]))){3})\\/(([0-9])|([12][0-9])|(3[0-2]))$") ){
        continue;
    }

    DE.box.alert("IP 입력을 확인 바랍니다.");
    return;
}
반응형

'프로그래밍' 카테고리의 다른 글

stl::map insert failed  (0) 2024.05.22
AES GCM Mode  (0) 2024.05.22
RegSystemToUser  (0) 2024.05.22
[ C++ ] 데이터모델  (2) 2014.09.21
SplitString ( CString Parser )  (0) 2014.07.14