Jump to content

[SOLVED] validate float


asmith

Recommended Posts

This falls under Regex

http://www.phpfreaks.com/forums/index.php/board,43.0.html

anyway , do this quick test  ;D

<?php
$test = array(
"5.01",
"5",
"5.001",
"0.05",
"6650.5",
"1.5",
"2.323"
);

// if there's a dot, min 1 no max 2 no..
$regex = '/^\d+(.\d{1,2})?$/';

// test numbers ...
foreach ($test as $number) {
if (preg_match($regex, $number)) {
echo "valid ";
} else {
echo "invalid ";
}
echo $number."<Br>";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/79383-solved-validate-float/#findComment-401871
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.