메뉴 건너뛰기

2014.03.01 21:55

check_inputbox.js

조회 수 5407 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
/*-------------------------------------------------------------------------------*/
/*
한글의 경우 키 입력시 바로바로 작업이 안되기 때문에
onchange 와 onblur 등 이벤트도 같이 등록.
*/
 // 한글만 입력받기 (초성체 무시) 
// 나머지 글자 무시 
function nr_han(this_s,type){ 
    /* 
    type 
    -> 'c' : 초성 포함 
    -> 's' : 초성 포함 + 공백 포함 
    -> '' : 초성, 공백 무시 
    */ 
    temp_value = this_s.value.toString(); 
    regexp = ''; 
    repexp = ''; 
    switch(type){ 
        case 'c': regexp = /[^ㄱ-ㅎ가-�R]/g;break; 
        case 's': regexp = /[^ㄱ-ㅎ가-�R\s]/g;break; 
        case '':    regexp = /[^가-�R]/g; break; 
        default : regexp = /[^ㄱ-ㅎ가-�R\s]/g; 
    } 
    if(regexp.test(temp_value)) 
    { 
        temp_value = temp_value.replace(regexp,repexp); 
        this_s.value = temp_value; 
    } 
} 
  
 /*-------------------------------------------------------------------------------*/
 // 한글만 입력받기 (초성체 포함)
// 나머지 글자 무시 
function nr_han_cho(this_s){
 nr_han(this_s,'c');
}
 /*-------------------------------------------------------------------------------*/
 // 한글만 입력받기 (초성체 포함, 공백 포함)
// 나머지 글자 무시
function nr_han_cho_space(this_s){
 nr_han(this_s,'s');
}

/*-------------------------------------------------------------------------------*/
function nr_numeng(this_s){
 temp_value = this_s.value.toString();
 regexp = /[^0-9a-zA-Z]/g;
 repexp = '';
 temp_value = temp_value.replace(regexp,repexp);
 this_s.value = temp_value;
}
 /*-------------------------------------------------------------------------------*/
// 나머지 글자 무시
function nr_num(this_s,type){
 /*
 type
 -> 'int' : 양의 정수
 -> 'float' : 양의 실수
 -> '-int' : 음의 정수 포함
 -> '-int' : 음의 실수 포함
 */
 temp_value = this_s.value.toString();
 regexp = /[^-\.0-9]/g;
 repexp = '';
 temp_value = temp_value.replace(regexp,repexp);
 regexp = '';
 repexp = '';
 switch(type){
  case 'int':  regexp = /[^0-9]/g; break;
  case 'float':regexp = /^(-?)([0-9]*)(\.?)([^0-9]*)([0-9]*)([^0-9]*)/; break;
  case '-int': regexp = /^(-?)([0-9]*)([^0-9]*)([0-9]*)([^0-9]*)/;break;
  case '-float':regexp = /^(-?)([0-9]*)(\.?)([^0-9]*)([0-9]*)([^0-9]*)/; break;
  default : regexp = /[^0-9]/g; break;
 }
 switch(type){
  case 'int':repexp = '';break;
  case 'float':repexp = '$2$3$5';break;
  case '-int': repexp = '$1$2$4';break;
  case '-float':repexp = '$1$2$3$5'; break;
  default : regexp = /[^0-9]/g; break;
 }
 temp_value = temp_value.replace(regexp,repexp);
 this_s.value = temp_value;
}
// 양의 정수만 입력받기
function nr_num_int(this_s){
 nr_num(this_s,'int');
}
// 양의 실수만 입력받기
function nr_num_float(this_s){
 nr_num(this_s,'float');
}
 /*-------------------------------------------------------------------------------*/
 // 영어만 입력받기  (대소문자)
// 나머지 글자 무시
function nr_eng(this_s,type){
 temp_value = this_s.value.toString();
 regexp = '';
 repexp = '';
 switch(type){
  case 'small':regexp = /[^a-z]/g;break;
  case 'big':regexp = /[^A-Z]/g;break;
  case 'all':regexp = /[^a-z]/i;break;
  default :regexp = /[^a-z]/i;break;
 }
 temp_value = temp_value.replace(regexp,repexp);
 this_s.value = temp_value;
}
 // 영어만 입력받기  (소문자)
// 나머지 글자 무시
function nr_eng_small(this_s){
 nr_eng(this_s,'small');
}
 // 영어만 입력받기  (대문자)
// 나머지 글자 무시
function nr_eng_big(this_s){
 nr_eng(this_s,'big');
}
 /*-------------------------------------------------------------------------------*/

// 주민등록 번호 규격에 맞게 123456-1234567  //검증하지 않음.
// 나머지 글자 무시
function nr_jumin(this_s){
 temp_value = this_s.value.toString();
 temp_value = temp_value.replace(/[^0-9]/g,'');
 temp_value = temp_value.substr(0,13);
 temp_value = temp_value.replace(/([0-9]{6})([0-9]{7}$)/,"$1-$2");
 this_s.value = temp_value;
}
  
 /*-------------------------------------------------------------------------------*/
 // 사업자 등록 번호 규격에 맞게 123-12-12345  //검증하지 않음.
// 나머지 글자 무시
function nr_company_num(this_s){
 temp_value = this_s.value.toString();
 temp_value = temp_value.replace(/[^0-9]/g,'');
 temp_value = temp_value.substr(0,10);
 temp_value = temp_value.replace(/([0-9]{3})([0-9]{2})([0-9]{5}$)/,"$1-$2-$3");
 this_s.value = temp_value;
}
 /*-------------------------------------------------------------------------------*/
 /*
 * 숫자와 - 만 사용가능
 */
function  nr_hyphen_num(this_s){
 temp_value = this_s.value.toString();
 temp_value = temp_value.replace(/[^0-9^-]/g,'');
 this_s.value = temp_value;
}
 function  nr_tel_num(this_s){
 temp_value = this_s.value.toString();
 temp_value = temp_value.replace(/[^0-9^-]/g,'');
 this_s.value = temp_value;
}
/*
// 관리자 번호 앞에 9자리 삭제
function nr_Adminno_Cut(adminno)
{
 if(adminno.length != 19)
  return adminno
  adminno = adminno.substr(9, 10);
 
 return adminno;
}
*/
 // 관리자 번호 앞에 9자리 삭제
function nr_Adminno_Cut(adminno)
{
 if(adminno.length != 20)
  return adminno
  adminno = adminno.substr(9, 10);
 
 return adminno;
}
 /*
// 날짜에 - 추가
function nr_Date_Paste(date)
{
 if(date.length != 8)
  return date;
  date = date.substr(0, 4) + "-" + date.substr(4, 2) + "-" + date.substr(6, 2);
 
 return date;
}
*/
 // 날짜에 - 삭제
function nr_Date_Cut(date)
{
 if(adminno.length != 8)
  return date
  date = date.substr(0, 4) + "-" + date.substr(5, 2) + "-" + date.substr(7, 2);
 
 return date;
}

// 날짜에 - 삭제
function nr_Date_Cut(date)
{
 if(date.length != 10)
  return date;
  date = date.substr(0, 4) + date.substr(5, 2) + date.substr(8, 2);
 
 return date;
}

// ,추가
function comma_paste(this_s)
{
 fvalue = this_s.value.toString();
 
    fvaluenum = fvalue.length; 
    
    if(fvaluenum>3){
        comma=Math.ceil(fvaluenum/3)-1;
        substart = 0;
         for(x=comma; x>=0; x--){
            sublast = fvaluenum-(x*3);
  
            val=fvalue.substring(substart, sublast);
            substart = sublast;
             if(x==comma) vall = val + ',';
            else if(x==0) vall = vall + val;
            else vall = vall + val + ',';
        }
        
        this_s.value = vall;
    }
    else 
    {
        this_s.value = fvalue;
    }
}
 // , 제거함수
function comma_cut(this_s)
{
 restring = this_s.value.toString();
 
    if(restring.search(',')){
        exp=restring.split(',');
        for(t=0 ; ; t++){
            if(!exp[t]) break;

            if(t==0){
                restring = exp[t];
            } else {
                restring = restring + exp[t];
            }
        }
    }
    
    this_s.value = restring;
}

// 정해진 숫자 길이를 넘기면 다음포커스로 이동
function count_check(this_s, this_e, cnt)
{
 nr_num_int(this_s);
 
 restring = this_s.value.toString();
 
 if(restring.length >= cnt)
 {
  this_e.focus();
 }
} 

List of Articles
번호 제목 날짜 조회 수
147 자바스크립트로 네트워크 연결 확인하기 (Navigator onLine Property) file 2015.06.19 6197
146 정규식을 이용한 실시간 콤마(comma) 넣기 2015.06.19 7876
145 정규식을 이용한 콤마(comma) 제거하기 2015.06.19 6804
144 텍스트박스(input type = "text") 숫자 증가, 감소 시키기 - 쇼핑몰 주문 수량 file 2015.06.19 12281
143 Checkbox : 체크박스 체크여부 확인 file 2015.06.19 19010
142 마우스 드래그, 오른쪽 팝업메뉴, 선택 막기 (IE11, 파이어폭스, 크롬 확인) 2015.06.19 8577
141 예제 - 자바스크립트로 현재 달의 달력 만들기 (calendar) 2015.06.19 10061
140 핸드폰 번호 일부 마스킹크 작업 (정규식 이용) 2015.06.19 10741
139 창에 대한 정보얻기 (창 크기, 창 위치) file 2015.06.19 7297
138 Location 객체 - URL 파싱 - URL에서 전달인자 추출하기 함수 작성 file 2015.06.19 8523
137 예제 - 이미지를 원본 크기로 볼 수 있도록 새창으로 열기 확장 (리사이징 및 이미지 드래그) file 2015.06.19 6798
136 창 크기 최대화 시키기 file 2015.06.19 12222
135 JSON API - JSON.parse(), JSON.stringify() ( json 형태의 문자열을 JSON객체로 , JSON객체를 문자열로 ) file 2015.06.19 6289
134 자바스크립트 API 문서 2015.06.19 9086
133 공백 검사 함수 2015.06.19 14586
132 자바스크립트 아이디 기억하기 기능 구현 (쿠키저장) file 2015.06.19 10924
131 [라디오버튼 오류 체크] 간단한 문제 예제 file 2015.06.19 7712
130 iframe사용시 높이 자동 조절 2015.06.19 6958
129 이벤트 - 페이지 로드 후 이벤트 처리하기 ( window.onload ) file 2015.06.19 10871
128 jquery offset()을 이용한 부드러운 스크롤 이동 2016.09.01 7277
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved