숫자만 입력받는 함수인데요? 정정좀해주세요 채택완료

10년 전 조회 3,089

메인창은  가로, 세로값을 넣는거예요.
물론 여기에 입력한값이 숫자만 입력하도록 프로그램을 짜보았는데..
어디서 잘못되었는지 묘안이 안떠오르네요..
가로 변수의 htnl name = x
세로 변수의 html name = y  
부탁드려요..

<?
if (($x == "") || ($y == ""))
{
  echo("
        <script>
        window.alert('제대로 공란없이 입력해 주세요');
        history.go(-1);
        </script>");
}

function tx($x)
{
    $textx = $x;
    $textx = ereg_replace(" ","",$textx);

    for ($i = 0; $i <= strlen($textx); $i++)
    {
        $temp = substr($textx,$i,1);

        if (ereg("([0-9]{1})","$temp"))
      {
            $xx = $temp;
        }
    }
    return $xx;
}

function ty($y)
{
    $texty = $y;
    $texty = ereg_replace(" ","",$texty);

    for ($i = 0; $i <= strlen($texty); $i++)
  {
        $temp = substr($texty,$i,1);

        if (ereg("([0-9]{1})","$temp"))
        {
            $yy = $temp;
        }
    }
    return $yy;
}


if (($x != tx($x)) || ($y != ty($y)))
{
    echo("
            <script>
            window.alert('제대로 숫자를 입력해 주세요');
            history.go(-1);
            </script>");
}
?>  

답변 1개

채택된 답변
+20 포인트
!= 인 비교연산자가 아니라..... !(....)



if (!($x = tx($x)) || !($y = ty($y)))&nbsp; &nbsp; // !의 위치가 중요하다.

{

&nbsp; echo("

&nbsp; &nbsp; &nbsp; &nbsp; <script>

&nbsp; &nbsp; &nbsp; &nbsp; window.alert('제대로 숫자를 입력해 주세요');

&nbsp; &nbsp; &nbsp; &nbsp; history.go(-1);

&nbsp; &nbsp; &nbsp; &nbsp; </script>");

}



이렇게 해보세요.
로그인 후 평가할 수 있습니다

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

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고