You are here: Re: Having expression migranes « All PHP « IT news, forums, messages
Re: Having expression migranes

Posted by Rik on 05/08/06 22:10

jenngra@gmail.com wrote:
> eep, sorry rik, trying to sort this :( , could you pls reprint showing
> some incoming $string, and how it works, where it can go into an error
> block/routine - or continue running? BEST REGARDS--Jennifer.

$data is the variable to be checked.

isfloat($data)
=> checks wether the given variable is a float.

number_format($data, 2, '.', '')==$data
=> checks wether the float is formatted with the right decimal-seperator,
and has 2 decimals

$data >=$min;
=> checks wether the float is greater than or equal to the minimum

$data <=$max
=> checks wether the float is smaller than or equal to the maximum

These four combined give tha validation you asked for.

In this code:
$min = 0.00;
$max = 9999999.00
$pass = (isfloat($data) && number_format($data, 2, '.', '')==$data &&
$data >= $min && $data<=$max);

$pass is set to a boolean: true if it meets your conditions, false
otherwise.

You could also do it like this:
$min = 0.00;
$max = 9999999.00
if(isfloat($data) && number_format($data, 2, '.', '')==$data &&
$data >= $min && $data<=$max){
// run your code
} else {
//display error, exit function, whatever you desire.
}

I am NOT explaining the regex to you, that's even more work then writing the
damn thing :-)
It was not enterily right do, it should be:
'/^(0\.[0-9]{2}|[1-9][0-9]{0,5}\.[0-9]{2}|[1-9][0-9]{6}[0-8]\.[0-9]{2}|99999
9
9\.00)$/'
The regex can be applied like;

if(preg_match('the_regex_i_gave_you', $data){
//run your code
} else {
//display error, exit function, whatever you desire.
}

Grtz,
--
Rik Wasmus

 

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

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