gaga.validation.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. /*
  2. * Form Validation Java Script written by gagamel
  3. *
  4. * Copyright (c) 2017 gagamel
  5. * Dual licensed under GPL (GPL-LICENSE.txt) licenses.
  6. *
  7. * $Date: 2017-09-20 $
  8. * $Modify: 2019-03-07 $
  9. *
  10. * Using)
  11. * 1. Add "data-valid-type" and "data-valid-name" attribute to Elements of form
  12. * ex) <input type="text" name="userNm" data-valid-type="alphaNumeric" data-valid-name="User Name"/>
  13. *
  14. * 2. data-valid-type
  15. * numeric, alphaNumeric, email, cellPhone, ipAddress
  16. *
  17. * 3. When submit a form, call "validation()" function.
  18. * ex)
  19. * if (!$('#aForm').validation())
  20. * return;
  21. */
  22. (function($) {
  23. /**
  24. * Spring Security를 사용하는 경우 Default로 CSRF(Cross Site Request Forgery)가 활성화 되어 있다.
  25. * 이 때문에 $.ajax 함수를 호출 시 404 에러가 발생한다. 이는 다음과 같이 해결한다.
  26. *
  27. * 1. SecurityConfig에 csrf().disable() 설정. <= CSRF(Cross Site Request Forgery) 해제
  28. * 또는
  29. * 2. Thymeleaf에서는 csrf 토큰이 hidden input에 자동으로 추가되어 있음으로 아래와 같이 ajax 호출 시 토큰을 Header에 설정한다.
  30. */
  31. /*var token = $("meta[name='_csrf']").attr("content");
  32. var header = $("meta[name='_csrf_header']").attr("content");
  33. $.ajaxSend(function(e, xhr, options) {
  34. xhr.setRequestHeader(header, token);
  35. });*/
  36. });
  37. var gagajf = {
  38. /**
  39. * @type : function
  40. * @access : public
  41. * @desc : 값이 null 이거나 white space 문자로만 이루어진 경우 true를 리턴한다.
  42. * <pre>
  43. * gagajf.isNull(" ");
  44. * </pre>
  45. * 위와같이 사용했을 경우 true를 리턴한다.
  46. * @param : value - 필수 입력 값
  47. * @return : boolean. null(혹은 white space) 여부
  48. * @author : gagamel
  49. */
  50. isNull : function(value) {
  51. if (value == null || (typeof(value) == "string" && value.trim() == ""))
  52. return true;
  53. return false;
  54. },
  55. /**
  56. * @type : function
  57. * @access : public
  58. * @desc : 값이 null str로 true를 리턴한다.
  59. * <pre>
  60. * gagajf.convNull(item.value, '');
  61. * </pre>
  62. * 위와같이 사용했을 경우 item.value 가 null일경우 ''을 리턴한다.
  63. * @param : value - 필수 입력 값
  64. * @param : str - 필수 입력 값
  65. * @return : value or str
  66. * @author : gagamel
  67. */
  68. convNull : function(value, str) {
  69. if (value == null)
  70. return str;
  71. return value;
  72. },
  73. /**
  74. * 유효한 이벤트 키코드인지 체크
  75. * @return : 유효한 이벤트 키코드이면 키코드 값, 아니면 -1
  76. * @since : 2017/09/20
  77. * @author : gagamel
  78. */
  79. getKeyCode : function() {
  80. // 이벤트 객체와 문자 코드를 호환 가능한 방식으로 얻는다.
  81. var e = event || window.event; // 키 이벤트 객체
  82. var keyCode = e.charCode || e.keyCode; // 어떤 키가 눌러졌는가?
  83. // console.log('keyCode: ' + keyCode);
  84. // Ctrl 키나 Alt 키, ASCII 제어문자, 화살표 등 skip
  85. if (e.ctrlKey || e.altkey || keyCode < 47) {
  86. return -1;
  87. }
  88. return keyCode;
  89. },
  90. /**
  91. * 값이 정규표현식에 부합하는지는 체크한다.
  92. * @param : el - 엘리먼트
  93. * @param : regexp - 정규표현식
  94. * @param : type - 엘리먼트 type
  95. * @return : 부합하는 경우 true, 그 외 false
  96. * @since : 2017/09/21
  97. * @author : gagamel
  98. */
  99. testRegexp : function(el, regexp, type) {
  100. var val = $(el).val();
  101. if (type == 'integer' || type == 'real') {
  102. // 콤마(,) 제거
  103. val = val.removeComma();
  104. }
  105. if (!regexp.test(val)) {
  106. mcxDialog.alertC($(el).data('validName') + '의 형식이 잘못되었습니다.', {
  107. sureBtnText: "확인",
  108. sureBtnClick: function() {
  109. $(el).select();
  110. $(el).focus();
  111. }
  112. });
  113. return false;
  114. }
  115. return true;
  116. },
  117. /**
  118. * alert 메시지
  119. * @param : el - 엘리먼트
  120. * mgsType - 메시지유형(input, select)
  121. * @since : 2017/09/21
  122. * @author : gagamel
  123. */
  124. alertMessage : function(el, mgsType) {
  125. var validNm = $(el).data('validName');
  126. if (mgsType == 'input') {
  127. mcxDialog.alertC(validNm + '을(를) 입력해 주세요.', {
  128. sureBtnText: "확인",
  129. sureBtnClick: function() {
  130. $(el).focus();
  131. }
  132. });
  133. } else if (mgsType == 'select') {
  134. mcxDialog.alertC(validNm + '을(를) 선택해 주세요.', {
  135. sureBtnText: "확인",
  136. sureBtnClick: function() {
  137. $(el).focus();
  138. }
  139. });
  140. }
  141. },
  142. /**
  143. * 체크박스와 라디오버튼을 선택한 것이 있는지 체크한다.
  144. * @param : el - 엘리먼트
  145. * mgsType - 메시지유형(input, select)
  146. * @since : 2017/09/21
  147. * @author : gagamel
  148. */
  149. isCheckedCheckbox : function(el) {
  150. $(el).each(function(idx) {
  151. if ($(el).eq(idx).is(':checked')) {
  152. return true;
  153. } else {
  154. return false;
  155. }
  156. });
  157. },
  158. /**
  159. * 비밀번호 체크
  160. * 1.영문대문자, 영문소문자, 특수문자, 숫자로만 구성
  161. * 2.이 중에 3가지 이상으로 구성 시 8자 이상, 2가지 이상으로 구성 시 10자 이상
  162. * @param : el - 엘리먼트
  163. * @since : 2017/09/21
  164. * @author : gagamel
  165. */
  166. checkPassword : function(el) {
  167. var passwd = $(el).val();
  168. var cnt = 0;
  169. if (/[a-z]{1,}/.test(passwd)) cnt++;
  170. if (/[A-Z]{1,}/.test(passwd)) cnt++;
  171. if (/[0-9]{1,}/.test(passwd)) cnt++;
  172. if (/[\~,\!,\@,\#,\$,\%,\^,\&,\*,\(,\),\_,\?,\{,\},\[,\]]{1,}/.test(passwd)) cnt++;
  173. if (cnt >= 3) {
  174. if (passwd.length < 8) {
  175. mcxDialog.alertC('3가지 이상으로 구성 시 8 자리 이상으로 입력해 주세요.', {
  176. sureBtnText: "확인",
  177. sureBtnClick: function() {
  178. $(el).select();
  179. $(el).focus();
  180. }
  181. });
  182. return false;
  183. }
  184. } else if (cnt >= 2) {
  185. if (passwd.length < 10) {
  186. mcxDialog.alertC('2가지 이상으로 구성 시 10 자리 이상으로 입력해 주세요.', {
  187. sureBtnText: "확인",
  188. sureBtnClick: function() {
  189. $(el).select();
  190. $(el).focus();
  191. }
  192. });
  193. return false;
  194. }
  195. } else {
  196. mcxDialog.alertC('대/소문자, 특수문자, 숫자로 구성해 주세요.', {
  197. sureBtnText: "확인",
  198. sureBtnClick: function() {
  199. $(el).select();
  200. $(el).focus();
  201. }
  202. });
  203. return false;
  204. }
  205. return true;
  206. },
  207. /**
  208. * 필수입력항목 엘리먼트를 체크해서 alert를 표시한다.
  209. */
  210. checkRequired : function(oForm) {
  211. var isInvalid = true;
  212. $(oForm).find(':input').each(function(idx, el) {
  213. if ($(el).attr('required') != 'required')
  214. return true;
  215. var type = $(el).attr('type');
  216. if (!type) type = 'select';
  217. // var msg = $(el).data('validName');
  218. switch (type) {
  219. case 'text':
  220. case 'password':
  221. case 'textarea':
  222. // case 'select-one':
  223. var value = $(el).val();
  224. if (!gagajf.isNull(value))
  225. return true;
  226. gagajf.alertMessage($(el), 'input');
  227. isInvalid = false;
  228. return false;
  229. case 'select':
  230. var value = $(el).val();
  231. if (!gagajf.isNull(value))
  232. return true;
  233. gagajf.alertMessage($(el), 'select');
  234. isInvalid = false;
  235. return false;
  236. case 'checkbox':
  237. case 'radio':
  238. if (gagajf.isCheckedCheckbox($(el)))
  239. return true;
  240. gagajf.alertMessage($(el), 'select');
  241. isInvalid = false;
  242. return false;
  243. case 'file':
  244. var value = $(el).val();
  245. if (!gagajf.isNull(value))
  246. return true;
  247. gagajf.alertMessage($(el), 'select');
  248. isInvalid = false;
  249. return false;
  250. }
  251. });
  252. return isInvalid;
  253. },
  254. /**
  255. * 값이 형식에 맞는지 패턴을 체크한다.
  256. */
  257. checkPattern : function(oForm) {
  258. var isInvalid = true;
  259. $(oForm).find('input').each(function(idx, el) {
  260. if (gagajf.isNull($(el).val()))
  261. return true;
  262. var validType = $(el).data('validType');
  263. // data-valid-type이 지정되지 않은 엘리먼트는 skip
  264. if (!validType) return true;
  265. // 값이 없으면 skip
  266. if (gagajf.isNull($(el).val())) return true;
  267. switch (validType) {
  268. case 'numeric': // 숫자
  269. if (gagajf.testRegexp($(el), /^[0-9]+$/))
  270. return true;
  271. isInvalid = false;
  272. return false;
  273. case 'integer': // 정수
  274. if (gagajf.testRegexp($(el), /(^-?[0-9]+\d*$)|(^-$)/, 'integer'))
  275. return true;
  276. isInvalid = false;
  277. return false;
  278. case 'real': // 실수
  279. if (gagajf.testRegexp($(el), /^-?(([0-9]+\.?)|(\.?))\d*$/, 'real'))
  280. return true;
  281. isInvalid = false;
  282. return false;
  283. case 'alphaNumeric': // 알파벳+숫자
  284. if (gagajf.testRegexp($(el), /^[a-zA-Z0-9]+$/))
  285. return true;
  286. isInvalid = false;
  287. return false;
  288. case 'email': // 이메일
  289. if (gagajf.testRegexp($(el), /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/))
  290. return true;
  291. isInvalid = false;
  292. return false;
  293. case 'password': // 이메일
  294. if (gagajf.checkPassword($(el)))
  295. return true;
  296. isInvalid = false;
  297. return false;
  298. case 'cellPhone': // 휴대전화번호
  299. if (gagajf.testRegexp($(el), /^(01(?:0|1|[6-9])-(?:\d{3}|\d{4})-\d{4})$/))
  300. return true;
  301. isInvalid = false;
  302. return false;
  303. case 'phone': // 일반전화번호
  304. if (gagajf.testRegexp($(el), /^\d{2,3}-\d{3,4}-\d{4}$/))
  305. return true;
  306. isInvalid = false;
  307. return false;
  308. case 'ipAddress': // IP주소
  309. if (gagajf.testRegexp($(el), /^(([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}))$/))
  310. return true;
  311. isInvalid = false;
  312. return false;
  313. }
  314. });
  315. return isInvalid;
  316. },
  317. checkValue : function(oForm){
  318. var isInvalid = true;
  319. $(oForm).find('input').each(function(idx, el) {
  320. var validType = $(el).data('validType');
  321. // data-valid-type이 지정되지 않은 엘리먼트는 skip
  322. if (!validType) return true;
  323. // 값이 없으면 skip
  324. if (gagajf.isNull($(el).val())) return true;
  325. switch (validType) {
  326. case 'numeric': // 숫자
  327. //최대값
  328. if ($(el).attr("max")) {
  329. if ($(el).val() > $(el).attr("max")) {
  330. mcxDialog.alertC($(el).data('validName') + '은(는) 최대 ' + $(el).attr("max") + '보다 작아야 합니다.', {
  331. sureBtnText: "확인",
  332. sureBtnClick: function() {
  333. $(el).focus();
  334. }
  335. });
  336. isInvalid = false;
  337. }
  338. }
  339. //최소값
  340. if ($(el).attr("min")) {
  341. if ($(el).val() < $(el).attr("min")) {
  342. mcxDialog.alertC($(el).data('validName') + '은(는) 최소 ' + $(el).attr("min") + '보다 커야 합니다.', {
  343. sureBtnText: "확인",
  344. sureBtnClick: function() {
  345. $(el).focus();
  346. }
  347. });
  348. isInvalid = false;
  349. }
  350. }
  351. case 'integer': // 정수
  352. //최대값
  353. if ($(el).attr("max")) {
  354. if ($(el).val() > $(el).attr("max")) {
  355. mcxDialog.alertC($(el).data('validName') + '은(는) 최대 ' + $(el).attr("max") + '보다 작아야 합니다.', {
  356. sureBtnText: "확인",
  357. sureBtnClick: function() {
  358. $(el).focus();
  359. }
  360. });
  361. isInvalid = false;
  362. }
  363. }
  364. //최소값
  365. if ($(el).attr("min")) {
  366. if ($(el).val() < $(el).attr("min")) {
  367. mcxDialog.alertC($(el).data('validName') + '은(는) 최소 ' + $(el).attr("min") + '보다 커야 합니다.', {
  368. sureBtnText: "확인",
  369. sureBtnClick: function() {
  370. $(el).focus();
  371. }
  372. });
  373. isInvalid = false;
  374. }
  375. }
  376. case 'real': // 실수
  377. //최대값
  378. if ($(el).attr("max")) {
  379. if ($(el).val() > $(el).attr("max")) {
  380. mcxDialog.alertC($(el).data('validName') + '은(는) 최대 ' + $(el).attr("max") + '보다 작아야 합니다.', {
  381. sureBtnText: "확인",
  382. sureBtnClick: function() {
  383. $(el).focus();
  384. }
  385. });
  386. isInvalid = false;
  387. }
  388. }
  389. //최소값
  390. if ($(el).attr("min")) {
  391. if ($(el).val() < $(el).attr("min")) {
  392. mcxDialog.alertC($(el).data('validName') + '은(는) 최소 ' + $(el).attr("min") + '보다 커야 합니다.', {
  393. sureBtnText: "확인",
  394. sureBtnClick: function() {
  395. $(el).focus();
  396. }
  397. });
  398. isInvalid = false;
  399. }
  400. }
  401. }
  402. });
  403. return isInvalid;
  404. },
  405. /**
  406. * form을 validation 한다.
  407. * 예)
  408. * if (gagajf.validation('#registerForm');
  409. */
  410. validation : function(formId) {
  411. var $form = $(formId);
  412. if (!this.checkRequired($form))
  413. return false;
  414. if (!this.checkPattern($form))
  415. return false;
  416. if(!this.checkValue($form))
  417. return false;
  418. return true;
  419. },
  420. /**
  421. * formId의 input의 data-valid-type이 integer, real인 경우에 값에 comma(,)를 자동으로 붙여 표시한다.
  422. * 사용) gagajf.addCommaAtNumberFormattedInput('#registerForm');
  423. */
  424. addCommaAtNumberFormattedInput : function(formId) {
  425. $(formId).find('input').each(function(idx, el) {
  426. if ($(el).data('validType') == 'integer' || $(el).data('validType') == 'real') {
  427. $(el).val($(el).val().removeComma().addComma());
  428. }
  429. });
  430. },
  431. /**
  432. * formId의 input의 data-valid-type이 integer, real, numeric 인 경우에 값에 comma(,)를 자동으로 제거한다.
  433. * 사용) gagajf.removeCommaAtNumberFormattedInput('#registerForm');
  434. */
  435. removeCommaAtNumberFormattedInput : function(formId) {
  436. $(formId).find('input').each(function(idx, el) {
  437. if ($(el).data('validType') == 'integer' || $(el).data('validType') == 'real' || $(el).data('validType') == 'numeric') {
  438. $(el).val($(el).val().removeComma());
  439. }
  440. });
  441. },
  442. /**
  443. * Progress bar
  444. */
  445. showProgressbar : function(isLoading) {
  446. if (isLoading) {
  447. // Button disabled & progressBar creation
  448. //$('.btn').each(function(idx) { $(this).attr('disabled', true); });
  449. var load_AjaxSubmit = '<div id="load_AjaxSubmit" style="'
  450. + 'background: url(/ux/plugins/gaga/loader.gif); border-style: none; background-repeat: no-repeat; '
  451. + 'position: absolute; top: 45%; left: 50%; width: auto; '
  452. + 'z-index: 101; padding: 16px; margin: 5px;'
  453. + '"></div>';
  454. $('#content').append(load_AjaxSubmit);
  455. } else {
  456. // Button activated & progressBar remove
  457. //$('.btn').each(function(idx) { $(this).attr('disabled', false); });
  458. $('#load_AjaxSubmit').remove();
  459. }
  460. },
  461. /**
  462. * form의 데이터를 json으로 변환 후 ajax 방식으로 submit 한다.
  463. * 모든 form의 ajax 처리는 이것으로 진행한다.
  464. * <pre>
  465. * ajaxFormSubmit('/rest/commoncode/create', '#registerForm', jfRegisterSaveCallback);
  466. * </pre>
  467. * @param actionUrl - Request URL
  468. * @param formId - form ID
  469. * @param callbackFn - Callback function
  470. * @author gagamel
  471. * @since 2019. 4. 8
  472. */
  473. ajaxFormSubmit : function(actionUrl, formId, callbackFn) {
  474. // comma(,) 제거
  475. gagajf.removeCommaAtNumberFormattedInput(formId);
  476. var jsonData = JSON.stringify($(formId).serializeObject());
  477. $.ajax({
  478. type : 'POST',
  479. url : actionUrl,
  480. data : jsonData,
  481. dataType : 'json',
  482. beforeSend : function(xhr, settings) {
  483. // AJAX call
  484. xhr.setRequestHeader("AJAX", "true");
  485. // dataType: "json"일 때
  486. xhr.setRequestHeader('Accept', 'application/json');
  487. xhr.setRequestHeader('Content-Type', 'application/json');
  488. // Button disabled & progressBar creation
  489. gagajf.showProgressbar(true);
  490. },
  491. complete : function(xhr) {
  492. // Button abled & progressBar remove
  493. gagajf.showProgressbar(false);
  494. // 세션이 없다. 로그인 페이지로 이동
  495. if (xhr.status == 901) {
  496. mcxDialog.alertC('세션이 없습니다. 로그인 페이지로 이동합니다.', {
  497. sureBtnText: "확인",
  498. sureBtnClick: function() {
  499. document.location.href = "/error/noSession";
  500. }
  501. });
  502. }
  503. },
  504. success : function(result) {
  505. if (typeof(result.status) == 'undefined' || result.status == 200) { // 성공
  506. if (!gagajf.isNull(result.message)) {
  507. mcxDialog.alertC(result.message, {
  508. sureBtnText: "확인",
  509. sureBtnClick: function() {
  510. if (typeof(callbackFn) == "function") {
  511. callbackFn.call(this, result);
  512. }
  513. }
  514. });
  515. } else {
  516. if (typeof(callbackFn) == "function") {
  517. callbackFn.call(this, result);
  518. }
  519. }
  520. } else { // 실패
  521. if (!gagajf.isNull(result.error.message)) {
  522. mcxDialog.alert(result.error.message);
  523. }
  524. return;
  525. }
  526. },
  527. error : function(result) {
  528. console.log(result);
  529. mcxDialog.alert('오류로 인해 처리되지 않았습니다.');
  530. }
  531. });
  532. },
  533. /**
  534. * json 데이터를 가지고 ajax 방식으로 submit 한다.
  535. * 모든 ajax 처리는 이것으로 진행한다.
  536. * <pre>
  537. * gagajf.removeCommaAtNumberFormattedInput('#registerForm'); // comma(,) 제거
  538. * var jsonData = JSON.stringify($('#registerForm').serializeObject());
  539. * gagajf.ajaxJsonSubmit('/rest/commoncode/create', jsonData, jfRegisterSaveCallback);
  540. * </pre>
  541. * @param actionUrl - Request URL
  542. * @param jsonData - Data of json format
  543. * @param callbackFn - Callback function
  544. * @author gagamel
  545. * @since 2019. 4. 8
  546. */
  547. ajaxJsonSubmit : function(actionUrl, jsonData, callbackFn) {
  548. $.ajax({
  549. type : 'POST',
  550. url : actionUrl,
  551. data : jsonData,
  552. dataType : 'json',
  553. beforeSend : function(xhr, settings) {
  554. // AJAX call
  555. xhr.setRequestHeader("AJAX", "true");
  556. // dataType: "json"일 때
  557. xhr.setRequestHeader('Accept', 'application/json');
  558. xhr.setRequestHeader('Content-Type', 'application/json');
  559. // Button disabled & progressBar creation
  560. gagajf.showProgressbar(true);
  561. },
  562. complete : function(xhr) {
  563. // Button abled & progressBar remove
  564. gagajf.showProgressbar(false);
  565. // 세션이 없다. 로그인 페이지로 이동
  566. if (xhr.status == 901) {
  567. mcxDialog.alertC('세션이 없습니다. 로그인 페이지로 이동합니다.', {
  568. sureBtnText: "확인",
  569. sureBtnClick: function() {
  570. document.location.href = "/error/noSession";
  571. }
  572. });
  573. }
  574. },
  575. success : function(result) {
  576. if (typeof(result.status) == 'undefined' || result.status == 200) { // 성공
  577. if (!gagajf.isNull(result.message)) {
  578. mcxDialog.alertC(result.message, {
  579. sureBtnText: "확인",
  580. sureBtnClick: function() {
  581. if (typeof(callbackFn) == "function") {
  582. callbackFn.call(this, result);
  583. }
  584. }
  585. });
  586. } else {
  587. if (typeof(callbackFn) == "function") {
  588. callbackFn.call(this, result);
  589. }
  590. }
  591. } else { // 실패
  592. if (!gagajf.isNull(result.error.message)) {
  593. mcxDialog.alert(result.error.message);
  594. }
  595. return;
  596. }
  597. },
  598. error : function(result) {
  599. console.log(result);
  600. mcxDialog.alert('오류로 인해 처리되지 않았습니다.');
  601. }
  602. });
  603. },
  604. /**
  605. * ajax 방식으로 파일을 업로드 한다.
  606. * <pre>
  607. * gagajf.ajaxFileUpload('/common/file/upload?subDir=notice', this.files[0], jfCallback);
  608. * </pre>
  609. * @param actionUrl - Request URL
  610. * @param file - A file to upload
  611. * @param callbackFn - Callback function
  612. * @param policy - Upload policy
  613. * @author gagamel
  614. * @since 2019. 7. 9
  615. */
  616. ajaxFileUpload : function(actionUrl, file, callbackFn, policy) {
  617. var formData = new FormData();
  618. formData.append("file", file);
  619. if (typeof policy != 'undefined') {
  620. formData.append("policy", policy);
  621. }
  622. $.ajax({
  623. type : 'POST',
  624. url : actionUrl,
  625. data : formData,
  626. dataType: 'json',
  627. processData : false, // true: data의 파일 형태가 query String으로 전송. false : non-processed data
  628. contentType : false, // multipart/form-data 형태로 전송되기 위한 옵션 값
  629. beforeSend : function(xhr, settings) {
  630. // AJAX call
  631. xhr.setRequestHeader("AJAX", "true");
  632. // Button disabled & progressBar creation
  633. gagajf.showProgressbar(true);
  634. },
  635. complete : function(xhr) {
  636. // Button abled & progressBar remove
  637. gagajf.showProgressbar(false);
  638. // 세션이 없다. 로그인 페이지로 이동
  639. if (xhr.status == 901) {
  640. mcxDialog.alertC('세션이 없습니다. 로그인 페이지로 이동합니다.', {
  641. sureBtnText: "확인",
  642. sureBtnClick: function() {
  643. document.location.href = "/error/noSession";
  644. }
  645. });
  646. }
  647. },
  648. success : function(result) {
  649. if (typeof(result.status) == 'undefined' || result.status == 200) { // 성공
  650. if (!gagajf.isNull(result.message)) {
  651. mcxDialog.alertC(result.message, {
  652. sureBtnText: "확인",
  653. sureBtnClick: function() {
  654. if (typeof(callbackFn) == "function") {
  655. callbackFn.call(this, result);
  656. }
  657. }
  658. });
  659. } else {
  660. if (typeof(callbackFn) == "function") {
  661. callbackFn.call(this, result);
  662. }
  663. }
  664. } else { // 실패
  665. if (!gagajf.isNull(result.error.message)) {
  666. mcxDialog.alert(result.error.message);
  667. }
  668. return;
  669. }
  670. },
  671. error: function(result) {
  672. console.log(result);
  673. mcxDialog.alert('오류로 인해 처리되지 않았습니다.');
  674. }
  675. });
  676. },
  677. /**
  678. * 대용량 json 데이터를 가지고 ajax 방식으로 submit 한다.
  679. * <pre>
  680. * gagajf.removeCommaAtNumberFormattedInput('#registerForm'); // comma(,) 제거
  681. * var jsonData = JSON.stringify($('#registerForm').serializeObject());
  682. * gagajf.ajaxJsonBatchSubmit('/rest/commoncode/create', jsonData, 1, 3, jfRegisterSaveCallback);
  683. * </pre>
  684. * @param actionUrl - Request URL
  685. * @param jsonData - Data of json format
  686. * @param callIdx - 호출인덱스(실제 호출한 횟수)
  687. * @param callCnt - 호출해야할횟수(몇 번 호출해야 하는지)
  688. * @param callbackFn - Callback function
  689. * @author gagamel
  690. * @since 2019. 4. 8
  691. */
  692. ajaxJsonBatchSubmit : function(actionUrl, jsonData, callIdx, callCnt, callbackFn) {
  693. $.ajax({
  694. type : 'POST',
  695. url : actionUrl,
  696. data : jsonData,
  697. dataType : 'json',
  698. beforeSend : function(xhr, settings) {
  699. // AJAX call
  700. xhr.setRequestHeader("AJAX", "true");
  701. // dataType: "json"일 때
  702. xhr.setRequestHeader('Accept', 'application/json');
  703. xhr.setRequestHeader('Content-Type', 'application/json');
  704. // Button disabled & progressBar creation
  705. if (callIdx == 1) { // 첫번째 호출이면
  706. gagajf.showProgressbar(true);
  707. }
  708. },
  709. complete : function(xhr) {
  710. // Button abled & progressBar remove
  711. if (callIdx == callCnt) { // 마지막 호출이면
  712. gagajf.showProgressbar(false);
  713. }
  714. // 세션이 없다. 로그인 페이지로 이동
  715. if (xhr.status == 901) {
  716. mcxDialog.alertC('세션이 없습니다. 로그인 페이지로 이동합니다.', {
  717. sureBtnText: "확인",
  718. sureBtnClick: function() {
  719. document.location.href = "/error/noSession";
  720. }
  721. });
  722. }
  723. },
  724. success : function(result) {
  725. if (callIdx == callCnt) { // 마지막 호출이면
  726. mcxDialog.alertC('성공적으로 처리되었습니다.', {
  727. sureBtnText: "확인",
  728. sureBtnClick: function() {
  729. if (typeof(callbackFn) == "function") {
  730. callbackFn.call(this, result);
  731. }
  732. }
  733. });
  734. } else {
  735. if (typeof(callbackFn) == "function") {
  736. callbackFn.call(this, result);
  737. }
  738. }
  739. },
  740. error : function(result) {
  741. console.log(result);
  742. mcxDialog.alert('오류로 인해 처리되지 않았습니다.');
  743. }
  744. });
  745. },
  746. /**
  747. * JQuery를 이용한 비동기 submit 처리
  748. * 파라미터의 명칭은 쿼리문과 동일하게 작성해야 한다.
  749. * <pre>
  750. * var params = new Object();
  751. * params.cdGb = "G900";
  752. * params.cd = "0202";
  753. *
  754. * gagajf.ajaxSubmit("/rest/commoncode/create", "json", jfCallback, params);
  755. *
  756. * or
  757. *
  758. * gagajf.ajaxSubmit("/rest/commoncode/create", "json", jfCallback);
  759. * </pre>
  760. * @param : actionUrl - action url. 필수
  761. * type - 처리결과 형식(text, html, xml, json). 필수
  762. * callback - type이 text, xml, json 일 때는 콜백함수명
  763. * type이 html일 때는 target명. 필수
  764. * params - 파라미터 오브젝트. 옵션
  765. * @author gagamel
  766. * @since 2019. 4. 8
  767. */
  768. ajaxSubmit : function(actionUrl, type, callback, params) {
  769. $.ajaxSetup({
  770. beforeSend: function(xhr, settings) {
  771. // AJAX call
  772. xhr.setRequestHeader("AJAX", "true");
  773. // type: "json"일 때
  774. if (type == "json") {
  775. xhr.setRequestHeader('Accept', 'application/json');
  776. xhr.setRequestHeader('Content-Type', 'application/json');
  777. }
  778. },
  779. complete: function(xhr) {
  780. // 세션이 없다. 로그인 페이지로 이동
  781. if (xhr.status == 901) {
  782. mcxDialog.alertC('세션이 없습니다. 로그인 페이지로 이동합니다.', {
  783. sureBtnText: "확인",
  784. sureBtnClick: function() {
  785. document.location.href = "/error/noSession";
  786. }
  787. });
  788. }
  789. }
  790. });
  791. if (!params) params = new Object();
  792. var paramData = $.param(params);
  793. // dataType: "json"일 때
  794. if (type == "json") {
  795. paramData = JSON.stringify(params);
  796. }
  797. $.post(actionUrl
  798. , paramData
  799. , function(result) {
  800. if (type == "html") {
  801. if (!gagajf.isNull(callback))
  802. $(document.getElementById(callback)).html(result);
  803. } else {
  804. // Callback 함수 호출
  805. if (typeof(callback) == "function")
  806. callback.call(this, result);
  807. }
  808. }
  809. , type);
  810. },
  811. /**
  812. * @type : function
  813. * @access : public
  814. * @desc : 기간의 시작일자와 종료일자를 설정한다.
  815. * <pre>
  816. * gagajf.setDate($('#sellStdt'), $('#sellEddt'), 't');
  817. * </pre>
  818. * @param : fromObj - 시작일자 오브젝트
  819. * @param : toObj - 종료일자 오브젝트
  820. * @param : type - 유형(오늘: t, 어제: y, 최근한주: 7d, 이번주: tw, 지난주: pw, 최근한달: 1m, 이번달: tm, 지난달: pm, 최근3개월: 3m
  821. * @since : 2019/08/09
  822. * @author : gagamel
  823. */
  824. setDate : function(tgtId, fromObj, toObj, type) {
  825. var date = new Date();
  826. if (type == '') { // 기간 X
  827. $(tgtId +' #' + fromObj).val('');
  828. $(tgtId +' #' + toObj).val('');
  829. } else if (type == 't') { // 오늘
  830. $(tgtId +' #' + fromObj).val(date.format("YYYY-MM-DD"));
  831. $(tgtId +' #' + toObj).val(date.format("YYYY-MM-DD"));
  832. } else if (type == 'y') { // 어제
  833. $(tgtId +' #' + fromObj).val(date.before(0, 0, 1).format("YYYY-MM-DD"));
  834. $(tgtId +' #' + toObj).val(date.before(0, 0, 1).format("YYYY-MM-DD"));
  835. } else if (type == '7d') { // 최근한주
  836. $(tgtId +' #' + fromObj).val(date.before(0, 0, 6).format("YYYY-MM-DD"));
  837. $(tgtId +' #' + toObj).val(date.format("YYYY-MM-DD"));
  838. } else if (type == 'tw') { // 이번주
  839. var wdays = date.getDate() - date.getDay();
  840. $(tgtId +' #' + fromObj).val((date.format('YYYY-MM-') + '01').toDate('YYYY-MM-DD').after(0, 0, wdays).format("YYYY-MM-DD"));
  841. $(tgtId +' #' + toObj).val((date.format('YYYY-MM-') + '01').toDate('YYYY-MM-DD').after(0, 0, wdays + 6).format("YYYY-MM-DD"));
  842. } else if (type == 'pw') { // 지난주
  843. var wdays = date.getDate() - date.getDay();
  844. $(tgtId +' #' + fromObj).val((date.format('YYYY-MM-') + '01').toDate('YYYY-MM-DD').after(0, 0, wdays - 7).format("YYYY-MM-DD"));
  845. $(tgtId +' #' + toObj).val((date.format('YYYY-MM-') + '01').toDate('YYYY-MM-DD').after(0, 0, wdays - 1).format("YYYY-MM-DD"));
  846. } else if (type == '1m') { // 최근한달
  847. $(tgtId +' #' + fromObj).val(date.before(0, 1, 0).after(0, 0, 1).format("YYYY-MM-DD"));
  848. $(tgtId +' #' + toObj).val(date.format("YYYY-MM-DD"));
  849. } else if (type == 'tm') { // 이번달
  850. $(tgtId +' #' + fromObj).val(date.format("YYYY-MM-") + '01');
  851. $(tgtId +' #' + toObj).val((date.format('YYYY-MM-') + '01').toDate('YYYY-MM-DD').after(0, 1, 0).before(0, 0, 1).format("YYYY-MM-DD"));
  852. } else if (type == 'pm') { // 지난달
  853. $(tgtId +' #' + fromObj).val(date.before(0, 1, 0).format("YYYY-MM-") + '01');
  854. $(tgtId +' #' + toObj).val((date.format('YYYY-MM-') + '01').toDate('YYYY-MM-DD').before(0, 0, 1).format("YYYY-MM-DD"));
  855. } else if (type == '3m') { // 최근3개월
  856. $(tgtId +' #' + fromObj).val(date.before(0, 3, 0).after(0, 0, 1).format("YYYY-MM-DD"));
  857. $(tgtId +' #' + toObj).val(date.format("YYYY-MM-DD"));
  858. }
  859. },
  860. /**
  861. * @type : function
  862. * @access : public
  863. * @desc : Set Cookie
  864. * <pre>
  865. * gagajf.setCookie("COOKIE_TODAY_PROD", "HUE00C105GE", 1);
  866. * </pre>
  867. * @param : name - 쿠키명
  868. * @param : value - 쿠키 값
  869. * @param : expiredays - 만료기간
  870. * @return : None
  871. * @since : 2019/07/01
  872. * @author : gagamel
  873. */
  874. setCookie : function(name, value, expiredays) {
  875. var todayDate = new Date();
  876. todayDate.setDate(todayDate.getDate() + expiredays);
  877. document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";";
  878. },
  879. /**
  880. * @type : function
  881. * @access : public
  882. * @desc : Get Cookie
  883. * <pre>
  884. * gagajf.getCookie("COOKIE_TODAY_PROD");
  885. * </pre>
  886. * @param : name - 쿠키명
  887. * @return : None
  888. * @since : 2019/07/01
  889. * @author : gagamel
  890. */
  891. getCookie : function(name) {
  892. var nameOfCookie = name + "=";
  893. var x = 0;
  894. while (x <= document.cookie.length) {
  895. var y = (x+nameOfCookie.length);
  896. if (document.cookie.substring(x, y) == nameOfCookie) {
  897. if ((endOfCookie=document.cookie.indexOf(";", y)) == -1) endOfCookie = document.cookie.length;
  898. return unescape(document.cookie.substring(y, endOfCookie));
  899. }
  900. x = document.cookie.indexOf(" ", x) + 1;
  901. if (x == 0) break;
  902. }
  903. return "";
  904. },
  905. /**
  906. * 데이터를 배열로 변환
  907. * 예)
  908. * convertToArray({cd: "KNE", cdNm: "KNE"});
  909. * @param : data - 데이터
  910. * @param : isCodeDisplay - 코드표시여부(true/false). default false
  911. * @author : gagamel
  912. * @since : 2019. 6. 7
  913. */
  914. convertToArray : function(data, isCodeDisplay) {
  915. if (data.length == 0)
  916. return [];
  917. if (typeof(isCodeDisplay) == 'undefined')
  918. isCodeDisplay = false;
  919. var arrValue = {};
  920. $.each(data, function(idx, item) {
  921. arrValue[item.cd] = (isCodeDisplay ? '[' + item.cd + '] ' : '') + item.cdNm;
  922. });
  923. return arrValue;
  924. }
  925. };
  926. /**
  927. * @type : function
  928. * @access : document
  929. * @desc : <input> 태그에 대한 키눌림에 대해 validation을 체크한다.
  930. * data-valid-type="numeric" : 숫자. 속성 지정시 숫자만 입력 가능
  931. * data-valid-type="integer" : 정수. 속성 지정시 숫자와 +, - 만 입력 가능
  932. * data-valid-type="real" : 실수. 속성 지정시 숫자와 +, -, . 만 입력 가능
  933. * data-valid-type="alphaNumeric" : 알파벳과 숫자. 속성 지정 시 영문과 숫자만 형식에 맞게 입력 가능
  934. * data-valid-type="date" : 숫자와 / 만 입력 가능
  935. * data-valid-type="korean" : 한글. 속성 지정 시 한글만 형식에 맞게 입력 가능
  936. * data-valid-type="email" : 이메일
  937. * data-valid-type="password" : 비밀번호
  938. * data-valid-type="cellPhone" : 휴대전화번호
  939. * data-valid-type="phone" : 일반전화번호
  940. * data-valid-type="ipAddress" : IP주소
  941. * data-valid-type="bizRegNo" : 사업자등록번호
  942. * <pre>
  943. * <input type="text" data-valid-type="numeric" />
  944. * <input type="text" data-valid-type="integer" />
  945. * <input type="text" data-valid-type="real" />
  946. * <input type="text" data-valid-type="alphaNumeric" />
  947. * <input type="text" data-valid-type="date" />
  948. * <input type="text" data-valid-type="korean" />
  949. * <input type="text" data-valid-type="email" />
  950. * <input type="text" data-valid-type="password" />
  951. * <input type="text" data-valid-type="cellPhone" />
  952. * <input type="text" data-valid-type="phone" />
  953. * <input type="text" data-valid-type="ipAddress" />
  954. * <input type="text" data-valid-type="bizRegNo" />
  955. * </pre>
  956. * @author : gagamel
  957. * @since : 2017/09/20
  958. */
  959. $(document).on("keyup", "[data-valid-type=numeric]", function() { $(this).val($(this).val().replace(/[^0-9]/gi,"")); });
  960. $(document).on("keydown", "[data-valid-type=numeric]", function() {
  961. var value = $(this).val();
  962. var keyCode = gagajf.getKeyCode();
  963. if (keyCode == -1)
  964. return true;
  965. if (!((keyCode >= 48 && keyCode <= 57 && !event.shiftKey) // 0 ~ 9
  966. || (keyCode >= 96 && keyCode <= 105) // 0 ~ 9 (Num Lock)
  967. )) {
  968. $(this).val(value);
  969. event.returnValue = false;
  970. }
  971. });
  972. $(document).on("blur", "[data-valid-type=integer]", function() { $(this).val($(this).val().removeComma().addComma()); });
  973. $(document).on("click", "[data-valid-type=integer]", function() { $(this).val($(this).val().removeComma()); });
  974. $(document).on("keyup", "[data-valid-type=integer]", function() { $(this).val($(this).val().replace(/[^0-9-\+]/gi,"")); });
  975. $(document).on("keydown", "[data-valid-type=integer]", function() {
  976. var value = $(this).val();
  977. var keyCode = gagajf.getKeyCode();
  978. if (keyCode == -1)
  979. return true;
  980. if (!((keyCode >= 48 && keyCode <= 57 && !event.shiftKey) // 0 ~ 9
  981. || (keyCode >= 96 && keyCode <= 105) // 0 ~ 9 (Num Lock)
  982. || (keyCode == 187 && event.shiftKey) // Shift 하고 +
  983. || (keyCode == 107) // + (Num Lock)
  984. || (keyCode == 189 && !event.shiftKey) // Shift 없이 -
  985. || (keyCode == 109) // - (Num Lock)
  986. )) {
  987. $(this).val(value);
  988. event.returnValue = false;
  989. }
  990. });
  991. $(document).on("blur", "[data-valid-type=real]", function() { $(this).val($(this).val().removeComma().addComma()); });
  992. $(document).on("click", "[data-valid-type=real]", function() { $(this).val($(this).val().removeComma()); });
  993. $(document).on("keyup", "[data-valid-type=real]", function() { $(this).val($(this).val().replace(/[^0-9-\+\.]/gi,"")); });
  994. $(document).on("keydown", "[data-valid-type=real]", function() {
  995. var value = $(this).val();
  996. var keyCode = gagajf.getKeyCode();
  997. if (keyCode == -1)
  998. return true;
  999. if (!((keyCode >= 48 && keyCode <= 57 && !event.shiftKey) // 0 ~ 9
  1000. || (keyCode >= 96 && keyCode <= 105) // 0 ~ 9 (Num Lock)
  1001. || (keyCode == 187 && event.shiftKey) // Shift 하고 +
  1002. || (keyCode == 107) // + (Num Lock)
  1003. || (keyCode == 189 && !event.shiftKey) // Shift 없이 -
  1004. || (keyCode == 109) // - (Num Lock)
  1005. || (keyCode == 190 && !event.shiftKey) // .
  1006. )) {
  1007. $(this).val(value);
  1008. event.returnValue = false;
  1009. }
  1010. });
  1011. $(document).on("keyup", "[data-valid-type=alphaNumeric]", function() { $(this).val($(this).val().replace(/[^a-zA-Z0-9]/gi, "")); });
  1012. $(document).on("keyup", "[data-valid-type=date]", function() { $(this).val($(this).val().replace(/[^0-9\/]/gi,"")); });
  1013. $(document).on("keyup", "[data-valid-type=calendar]", function() { $(this).val($(this).val().replace(/[^0-9\/]/gi,"")); });
  1014. $(document).on("blur", "[data-valid-type=calendar]", function() {
  1015. var val = $(this).val();
  1016. if(val==''){
  1017. return;
  1018. }
  1019. val = val.replace(/-/gi, "");
  1020. var temp = val.substring(0, 4)+" ";
  1021. if(Number(val.substring(4, 6))>12){
  1022. temp += "12";
  1023. }else if(Number(val.substring(4, 6))==0){
  1024. temp += "1";
  1025. }else{
  1026. temp += Number(val.substring(4, 6));
  1027. }
  1028. temp += " ";
  1029. if(Number(val.substring(6, 8))>31){
  1030. temp += "31";
  1031. }else if(Number(val.substring(6, 8))==0){
  1032. temp += "1";
  1033. }else{
  1034. temp += Number(val.substring(6, 8));
  1035. }
  1036. var date = new Date(temp);
  1037. var yyyy = date.getFullYear().toString();
  1038. var mm = (date.getMonth() + 1).toString();
  1039. var dd = date.getDate().toString();
  1040. $(this).val(yyyy + '-' + (mm[1] ? mm : '0'+mm[0])+ '-' + (dd[1] ? dd : '0'+dd[0]));
  1041. });
  1042. $(document).on("keyup", "[data-valid-type=korean]", function() { $(this).val($(this).val().replace(/[^가-힣]/gi, "")); });
  1043. $(document).on("keyup", "[data-valid-type=email]", function() { $(this).val($(this).val().replace(/[^a-zA-Z0-9\@\+\_\.\@\-]/gi, "")); });
  1044. $(document).on("keyup", "[data-valid-type=password]", function() { $(this).val($(this).val().replace(/[^a-zA-Z0-9\~\!\@\#\$\%\^\&\*\?\(\)\_\+\{\}\[\]]/gi, "")); });
  1045. $(document).on("keyup", "[data-valid-type=cellPhone]", function() { $(this).val($(this).val().replace(/[^\d-]/gi, "")); });
  1046. $(document).on("keydown", "[data-valid-type=cellPhone]", function() {
  1047. var value = $(this).val();
  1048. var keyCode = gagajf.getKeyCode();
  1049. if (keyCode == -1)
  1050. return true;
  1051. if (!((keyCode >= 48 && keyCode <= 57 && !event.shiftKey) // 0 ~ 9
  1052. || (keyCode >= 96 && keyCode <= 105) // 0 ~ 9 (Num Lock)
  1053. || (keyCode == 189 && !event.shiftKey) // Shift 없이 -
  1054. || (keyCode == 109) // - (Num Lock)
  1055. )) {
  1056. $(this).val(value);
  1057. event.returnValue = false;
  1058. }
  1059. });
  1060. $(document).on("keyup keydown paste change", "[data-valid-type=cellPhone]", function() {
  1061. $(this).val($(this).val().replace(/[^0-9]/g, "").replace(/(^02|^050[0-9]{1}|^1[0-9]{3}|^0[0-9]{2})([0-9]+)?([0-9]{4})$/,"$1-$2-$3").replace("--", "-"));
  1062. });
  1063. $(document).on("keyup", "[data-valid-type=phone]", function() { $(this).val($(this).val().replace(/[^\d-]/gi, "")); });
  1064. $(document).on("keydown", "[data-valid-type=phone]", function() {
  1065. var value = $(this).val();
  1066. var keyCode = gagajf.getKeyCode();
  1067. if (keyCode == -1)
  1068. return true;
  1069. if (!((keyCode >= 48 && keyCode <= 57 && !event.shiftKey) // 0 ~ 9
  1070. || (keyCode >= 96 && keyCode <= 105) // 0 ~ 9 (Num Lock)
  1071. || (keyCode == 189 && !event.shiftKey) // Shift 없이 -
  1072. || (keyCode == 109) // - (Num Lock)
  1073. )) {
  1074. $(this).val(value);
  1075. event.returnValue = false;
  1076. }
  1077. });
  1078. $(document).on("keyup", "[data-valid-type=ipAddress]", function() { $(this).val($(this).val().replace(/[^\d\.]/gi, "")); });
  1079. $(document).on("keydown", "[data-valid-type=ipAddress]", function() {
  1080. var value = $(this).val();
  1081. var keyCode = gagajf.getKeyCode();
  1082. if (keyCode == -1)
  1083. return true;
  1084. if (!((keyCode >= 48 && keyCode <= 57 && !event.shiftKey) // 0 ~ 9
  1085. || (keyCode >= 96 && keyCode <= 105) // 0 ~ 9 (Num Lock)
  1086. || (keyCode == 190 && !event.shiftKey) // .
  1087. )) {
  1088. $(this).val(value);
  1089. event.returnValue = false;
  1090. }
  1091. });
  1092. $(document).on("keyup", "[data-valid-type=bizRegNo]", function() { $(this).val($(this).val().replace(/[^0-9\-]/gi,"")); });