You can try

if  (ereg('[^0-9]',$value))
   {
     do something // if you form value string contains non numerics do
something
    }
     else
   {
     settype($value,"integer");  // Its a numeric so set the string to a
integer to allow normal < > etc testing.
   }


Mike

----- Original Message ----- 
From: "Rafael Soares" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, November 17, 2004 10:36 AM
Subject: [PHP-WIN] How to check if a *string* has only numbers...


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

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to