You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.3 KiB

  1. /************************************************************************************************************************
  2. * 해당 문자열의 regex 검사
  3. * @param regexType
  4. *************************************************************************************************************************/
  5. String.prototype.regex = function(regexType) {
  6. var phoneRegex = /^(01[016789]{1}|02|0[3-9]{1}[0-9]{1})([0-9]{3,4})([0-9]{4})$/,
  7. phoneWithHypenRegex = /^(01[016789]{1}|02|0[3-9]{1}[0-9]{1})-?([0-9]{3,4})-?([0-9]{4})$/,
  8. telRegex = /(^02.{0}|^01.{1}|[0-9]{3})([0-9]{3,4})([0-9]{4})/,
  9. telCheckRegex = /^\d{2,3}-\d{3,4}-\d{4}$/,
  10. uniqueID = /^[a-z][a-z0-9_]{2,19}$/g,
  11. emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
  12. str = this;
  13. switch(regexType) {
  14. case "phone" :
  15. var transNum = str.replace(/\s/gi, '').replace(/-/gi,'');
  16. if(transNum.length == 11 || transNum.length == 10) {
  17. if( phoneRegex.test(transNum) ) {
  18. transNum = transNum.replace(phoneWithHypenRegex, '$1-$2-$3');
  19. return transNum;
  20. }
  21. }
  22. return false;
  23. case "tel":
  24. var transNum = str.replace(/\s/gi, '').replace(/-/gi,'');
  25. transNum = transNum.replace(telRegex, '$1-$2-$3');
  26. if(telCheckRegex.test(transNum)) {
  27. return transNum;
  28. }
  29. return false;
  30. case "email":
  31. return emailRegex.test(str);
  32. case "biznum" :
  33. var checkID = new Array(1, 3, 7, 1, 3, 7, 1, 3, 5, 1),
  34. tmpBizID, i, chkSum=0, c2, remander,
  35. bizID = str.replace(/-/gi,'');
  36. for (i=0; i<=7; i++) chkSum += checkID[i] * bizID.charAt(i);
  37. c2 = "0" + (checkID[8] * bizID.charAt(8));
  38. c2 = c2.substring(c2.length - 2, c2.length);
  39. chkSum += Math.floor(c2.charAt(0)) + Math.floor(c2.charAt(1));
  40. remander = (10 - (chkSum % 10)) % 10 ;
  41. if (Math.floor(bizID.charAt(9)) == remander) return bizID.replace(/(\d{3})(\d{2})(\d{5})/, '$1-$2-$3');
  42. return false;
  43. case "uniqid" :
  44. return uniqueID.test(str);
  45. }
  46. };