테스트 사이트 - 개발 중인 베타 버전입니다

숫자 입력 유효성 체크 하기 입니다.

· 9년 전 · 264

form 문서에서 넘어온 특정값이 숫자만 입력 (예를 들어 전화번호 등)만 넘어오는것을 고려하여  넘어온 값이 숫자만  온것인지 혹은 문자가 혼재된 것인지 체크 합니다.


<%
/*
// 3-1. 숫자만 입력받기 , preg_match 활용
*/
if ( preg_match("/^([0-9]*){3,15}$/", $_POST[aaa]) ) {
  echo "this is a integer 정수입니다.";
} else {
  echo "this is a string 문자입니다";
}

/*
// 3-2. 숫자만 입력받기 , is_int 활용  , PHP 버그로 오작동
// 테스트 :  PHP 4.4.7  ,  PHP 5.2.9
*/
// 상황1 : 오작동
if (is_int($_POST[aaa]))
  echo "is_int 1 = 정수 this is a integer <br>";
else
  echo "is_int 1 = 문자 this is a string <br>";
// 상황2 : 오작동
$aaa = $_POST[aaa];
if (is_int($aaa))
  echo "is_int 2 = 정수 this is a integer <br>";
else
  echo "is_int 2 = 문자 this is a string <br>";
// 상황3 : 정상
if (is_int(111))
  echo "is_int 3 = 정수 this is a integer <br>";
else
  echo "is_int 3 = 문자 this is a string <br>";
%>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시글 목록

번호 제목
12307
12306
12305
12304
12303
JavaScript 계산기
12302
12301
12300
12299
12298
12297
12296
12295
12294
12293
12292
12291
12290
12289
12288
12287
12286
12285
12284
12283