자바스크립트 정규식을 이용한 데이터체크 > script

본문 바로가기

script

자바스크립트 정규식을 이용한 데이터체크

작성일 10-03-18 15:31

페이지 정보

작성자서방님 조회 241회 댓글 0건

본문

// 빈값 체크
function isEmpty(str)
{
 if ( str.match(/^$/) )
  return true;

 return false;
}

// 영문만 입력 체크
function onlyAlpha(str)
{
 var findStr = str.match(/[a-z]+/i);

 if ( str == findStr )
  return true;
 else
  return false;
}

// 숫자만 입력 체크
function onlyNumeric(str)
{
 var findStr = str.match(/[0-9]+/);

 if ( str == findStr )
  return true;
 else
  return false;
}

// 한글만 입력 체크
function onlyKorean(str)
{
 var findStr = str.match(/[가-힣ㄱ-ㅣ]+/);

 if ( str == findStr )
  return true;
 else
  return false;
}

// 이메일 입력 체크
function isEmail(str)
{
 var findStr = str.match(/[\w]+@[\w.]+\.[a-zA-Z]+/);

 if ( str == findStr )
  return true;
 else
  return false;
}

// 주소형식 체크
function isURL(str)
{
 var findStr = str.match(/https?:\/\/[\w+.]+[a-z]{2,}/);

 if ( str == findStr )
  return true;
 else
  return false;
}

댓글목록

등록된 댓글이 없습니다.

게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기