Saturday, December 1, 2018

is_numeric()



some thing in test

<?php
$strings = array('1820.20', '10002', 'wsl!12');
foreach ($strings as $testcase) {
    if (ctype_digit($testcase)) {
        echo "The string $testcase consists of all digits.\n";
    } else {
        echo "The string $testcase does not consist of all digits.\n";
    }
}
?>







<?php
function isFloat($value){
  return ((int)$value != $value) ;
}

isFloat('1.5') ;//return true
isFloat('15');//return false
isFloat('1e16');//return true
isFloat('foo');//return false
isFloat(5.98);//return true
isFloat(5);//return false

?>
echo "<br>";
<?php
echo var_dump(is_numeric(27.25));  echo "27.25"."<br>";
var_dump(is_numeric(2344));       echo "abc"."<br>";
var_dump(is_float(23));          echo "23"."<br>";
var_dump(is_float(23.5));        echo "23.5"."<br>";
var_dump(is_float(1e7));         echo ""."<br>"; //Scientific Notation
var_dump(is_float(true));         echo ""."<br>";
?>




<?php
if(is_numeric('dffgfgfgh')){echo "567727.25condition is ok";}
else{echo "not ok";}
?>

<br>
<?php
if(!is_numeric('dffgfgfgh')){echo "567727.25condition is ok";}
else{echo "not ok";}
?>



<?php
// validate alphanumeric 
$input="gfghfhfhgg1223445-5";
if(preg_match('/^[a-zA-Z]+[a-zA-Z0-9-]+$/', $input))
{
    echo "valid statment";
}
else
{
    //invalid
    echo "non valid statment";
}

?>

No comments:

Post a Comment

form validation

function formsubmit ( ) { var empname = document .getElementById ( 'emp_name' ). value ; var email = document .getElem...