473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to validate a number

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>";

}


Jul 17 '05 #1
3 1422
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
On Mon, 17 Jan 2005 21:12:23 +1300, "WindAndWaves" <ac****@ngaru.com>
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 .= "<LI>the tariffs range is between (in New Zealand
dollars): $min_rate and $max_rate </LI>";

}


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
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 .= "<LI>the tariffs range is between (in New Zealand
dollars): $min_rate and $max_rate </LI>";

}


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew | last post by:
Hi, How can I validate a date, like 3/26/04, before submitted? Thanks for any idea. -- Andrew
6
by: Abby Lee | last post by:
I must confirm the user enters a value for each fund they need. I do not know how many fund entries there will be...it's expandable to handle each users needs. I must varify each fund they enter is...
3
by: Mike P | last post by:
I have an xml doucument that I want to validate with a XSD schema. I'm new to this and I don't know exactly how I make the references at the top of the documents so that the XSD file will validate...
3
by: Poppy | last post by:
I have a text field I want to validate. It needs to store a number e.g "23.5", "10000" Is there any isnum() method in .net. TIA
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
2
by: Neo Geshel | last post by:
Greetings, I have a form with a telephone field. It is very specific, as it has four text boxes - the country code, area code, prefix and suffix. I can validate each of them individually, but...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
1
by: hhhhhhhh | last post by:
Hello all, When I run the application, it requires to enter Employee number, social, and name. I can enter any letter and number to call employee number, social and name. I do not know how to...
5
by: Abhishek | last post by:
Hi this is my another validator in javascript to validate the Phone Number :-) <script language='javascript'> function funcCheckPhoneNumber(ctrtxtMobile,e){ if(window.event){ var strkeyIE =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.