You are here: Re: Help with a regular expression for 0,1 or 2 decimal places « PHP « IT news, forums, messages
Re: Help with a regular expression for 0,1 or 2 decimal places

Posted by Phillip Oertel on 10/25/05 21:55

hi,

i'm not a regex guru myself, but the following regex should work - tabke
a look at my regex test setup ...

<?php

$test = array(
"1",
"1.",
"1.2",
"1.23",
"1.234",

"1234",
"1234.",
"1234.5",
"1234.56",
"1234.567"
);


// if there's a dot, we want at least one number after it.
$regex = '/^\d+(.\d{1,2})?$/';

// test all or numbers ...
foreach ($test as $number) {
if (preg_match($regex, $number)) {
echo "ok ";
} else {
echo "no ";
}
echo $number . "<br />\n";
}

?>

i don't think there's a difference between \d and [0-9], but again, i am
no expert ...

regards,
phillip

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация