429,045 Members | 1,305 Online
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

# how to validate a number

 P: n/a 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 .= "
• the tariffs range is between (in New Zealand dollars): \$min_rate and \$max_rate
• "; } Jul 17 '05 #1
3 Replies

 P: n/a WindAndWaves wrote: 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? 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 Jul 17 '05 #2

 P: n/a On Mon, 17 Jan 2005 21:12:23 +1300, "WindAndWaves" reverently intoned upon the aether: 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 .= "
• the tariffs range is between (in New Zealand dollars): \$min_rate and \$max_rate
• "; } Try the routines at the following link: http://prdownloads.sourceforge.net/o...s.zip?download 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 Jul 17 '05 #3

 P: n/a WindAndWaves wrote: 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 .= "
• the tariffs range is between (in New Zealand dollars): \$min_rate and \$max_rate
• "; } 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 Jul 17 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion.