# how to validate a number

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi Gurus

Excuse my ignorance.... I am just learning PHP and I am loving it - I am
just amazed by what it has to offer - it seems endless.

Anyway, I want to ask something very simple.  How can I for a value to be a
number between 0 and 99 or 0 and 99999?

I have included a code snippet of where I would like to add it.

TIA
- Nicolaas

// check MIN AND MAX RATE for validity (between 1 and 100,000)

if (\$min_rate >0 && \$max_rate <99999) {

\$sql .= " AND (a.rateMin >=\$min_rate AND a.rateMax <=\$max_rate) ";

\$humanSQL .= "<LI>the tariffs range is between (in New Zealand
dollars): \$min_rate and \$max_rate </LI>";

}

## Re: how to validate a number

WindAndWaves wrote:

This is explained in this section

XCI. Regular Expression Functions (Perl-Compatible)

of the PHP manual.

NM

--
convert uppercase WORDS to single keystrokes to reply

## Re: how to validate a number

reverently intoned upon the aether:

Try the routines at the following link:

The code inside them is reasonably well commented.

I would also suggest reading the following info as a starting place
unless you are already comfortable with handling SQL injection and XSS
issues.

http://www.owasp.org/documentation/topten.html

hope this helps,

Sean

"In the End, we will remember not the words of our enemies,
but the silence of our friends."

- Martin Luther King Jr. (1929-1968)

Photo Archive @ http://www.tearnet.com/Sean
Last Updated 29 Sept. 2004

## Re: how to validate a number

WindAndWaves wrote:

Hi there!

I prefer to use it in this way:
if (is_numeric(\$min_rate) && \$min_rate >0 && \$max_rate <99999)

sometimes could be some white spaces so you can use
is_numeric(trim(\$min_rate))

Narcis