Re: Re: How to check if a *string* has only numbers...

From: Date: Fri, 19 Nov 2004 13:18:13 +0000
Subject: Re: Re: How to check if a *string* has only numbers...
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-25000@lists.php.net to get a copy of this message
Better yet, use the right function :-) This script <?php $a = "1234567890"; $b = $a.$a; $c = $a."A"; echo "$a "; if (!is_numeric($a))
       echo "NOT ";
echo "numeric<br>"; echo "$b "; if (!is_numeric($b))
       echo "NOT ";
echo "numeric<br>"; echo "$c "; if (!is_numeric($c))
       echo "NOT ";
echo "numeric<br>"; ?> should provide this output 1234567890 numeric 12345678901234567890 numeric 1234567890A NOT numeric Luis user@domain.invalid wrote:
Hi, Have you tried regular expressions ? try them, they might do the trick Rui Francisco Rafael Soares wrote:
Hello people!!! I would like to check if a string contains only numbers, I really can’t realize how to do it. I tried is_int(), but it don’t work because the variable is a string (I used gettype() to check it) and is_int() returns NULL… It is to validate some data in a form. The variable I’m trying to test is the result of this script: $data = $_POST[‘data’]; // something like 123.456.789 $dataParts = explode($data); //these are the variable I have to check: $dataP1 = $dataParts[0]; $dataP2 = $dataParts[1]; $dataP3 = $dataParts[3]; gettype($dataP1), gettype($dataP2) and gettype($dataP3) return string gettype($dataParts) returns array Thanks in advance. Rafael Soares - AgênciaM Fone: +55 11 4616-1394


« previous php.windows (#25000) next »