473,406 Members | 2,217 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,406 software developers and data experts.

how to validate $_GET var is a positive integer?

I need to check the $_GET['idnum'] to make certain it is a positive integer.

is_integer($_GET['idnum']) is not working. I think it thinks it's a sting.
So I tried casting it to an int using, is_integer((int)$_GET['idnum']).
Then whatever I threw in the _GET variable passed as an integer, even
strings.

Any ideas or links or functions are much appreciated!
Jul 17 '05 #1
7 14045
*** NotGiven escribió/wrote (Mon, 6 Sep 2004 18:04:11 -0400):
I need to check the $_GET['idnum'] to make certain it is a positive integer.

is_integer($_GET['idnum']) is not working. I think it thinks it's a sting.
So I tried casting it to an int using, is_integer((int)$_GET['idnum']).
Then whatever I threw in the _GET variable passed as an integer, even
strings.


Manual says:

"To test if a variable is a number or a numeric string (such as form input,
which is always a string), you must use is_numeric()."

In any case, for most apps it's enough with (int)$_GET['idnum']; of course,
using that value in your calculations, not only to validate. The worst
problem you can face is that actual value is "3a" or "3.25" and you get a
3.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #2
right, and thanks. '3a' is exactly what I am trying to test for - I am
posting another main topic to cover this
"Alvaro G. Vicario" <kA*****************@terra.es> wrote in message
news:x4***************************@40tude.net...
*** NotGiven escribió/wrote (Mon, 6 Sep 2004 18:04:11 -0400):
I need to check the $_GET['idnum'] to make certain it is a positive
integer.

is_integer($_GET['idnum']) is not working. I think it thinks it's a
sting.
So I tried casting it to an int using, is_integer((int)$_GET['idnum']).
Then whatever I threw in the _GET variable passed as an integer, even
strings.


Manual says:

"To test if a variable is a number or a numeric string (such as form
input,
which is always a string), you must use is_numeric()."

In any case, for most apps it's enough with (int)$_GET['idnum']; of
course,
using that value in your calculations, not only to validate. The worst
problem you can face is that actual value is "3a" or "3.25" and you get a
3.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la
intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--

Jul 17 '05 #3
"NotGiven" wrote:
right, and thanks. ’3a’ is exactly what I am trying to
test for - I am
posting another main topic to cover this
"Alvaro G. Vicario" <kA*****************@terra.es> wrote in
message
news:x4***************************@40tude.net...
*** NotGiven escribió/wrote (Mon, 6 Sep 2004 18:04:11 -0400):
I need to check the $_GET[’idnum’] to make certain it is a positive integer.

is_integer($_GET[’idnum’]) is not working. I think it thinks it’s a sting.
So I tried casting it to an int using, is_integer((int)$_GET[’idnum’]). Then whatever I threw in the _GET variable passed as an integer, even strings.
Manual says:

"To test if a variable is a number or a numeric string (such as

form
input,
which is always a string), you must use is_numeric()."

In any case, for most apps it’s enough with

(int)$_GET[’idnum’]; of
course,
using that value in your calculations, not only to validate. The

worst
problem you can face is that actual value is "3a" or "3.25"

and you get a
3.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la
intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la

papelera
-+ I’m not a free help desk, please don’t e-mail me

your questions
--</font>


you can test integer this way

preg_match("/^\d+$/", $input)

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-validate...ict146910.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=491964
Jul 17 '05 #4
"NotGiven" wrote:
I need to check the $_GET[’idnum’] to make certain it is a
positive integer.

is_integer($_GET[’idnum’]) is not working. I think it
thinks it’s a sting.
So I tried casting it to an int using,
is_integer((int)$_GET[’idnum’]).
Then whatever I threw in the _GET variable passed as an integer, even strings.

Any ideas or links or functions are much appreciated!


As I responded to your other post..

preg_match("/^\d+$/", $inputvalue)

of course, "0" would also eval to True here.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-validate...ict146910.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=491966
Jul 17 '05 #5
*** NotGiven escribió/wrote (Mon, 6 Sep 2004 18:25:19 -0400):
right, and thanks. '3a' is exactly what I am trying to test for - I am
posting another main topic to cover this


That's the sort of situations where a regular expression (used in
preg_match) is the easiest way:

/^[0-9]{1,2}[a-z]{1}$/ ---> 1 or 2 digits plus exactly 1 letter
/^[0-9]{1}[a-z]{0,2}$/ ---> exactly 1 digit plus 0, 1 or 2 letters

etc.

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #6
thanks

"steve" <Us************@dbForumz.com> wrote in message
news:41**********@alt.athenanews.com...
"NotGiven" wrote:
right, and thanks. '3a' is exactly what I am trying to
test for - I am
posting another main topic to cover this
"Alvaro G. Vicario" <kA*****************@terra.es> wrote in
message
news:x4***************************@40tude.net...
*** NotGiven escribió/wrote (Mon, 6 Sep 2004 18:04:11 -0400):
> I need to check the $_GET['idnum'] to make

certain it is a positive
> integer.
>
> is_integer($_GET['idnum']) is not working. I

think it thinks it's a
> sting.
> So I tried casting it to an int using,

is_integer((int)$_GET['idnum']).
> Then whatever I threw in the _GET variable passed as an

integer, even
> strings.

Manual says:

"To test if a variable is a number or a numeric string (such as

form
input,
which is always a string), you must use is_numeric()."

In any case, for most apps it's enough with

(int)$_GET['idnum']; of
course,
using that value in your calculations, not only to validate. The

worst
problem you can face is that actual value is "3a" or "3.25"

and
you get a
3.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la
intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la

papelera
-+ I'm not a free help desk, please don't e-mail me

your questions
--</font>


you can test integer this way

preg_match("/^\d+$/", $input)

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL:
http://www.dbForumz.com/PHP-validate...ict146910.html
Visit Topic URL to contact author (reg. req'd). Report abuse:
http://www.dbForumz.com/eform.php?p=491964

Jul 17 '05 #7
thanks

"Alvaro G. Vicario" <kA*****************@terra.es> wrote in message
news:ck*****************************@40tude.net...
*** NotGiven escribió/wrote (Mon, 6 Sep 2004 18:25:19 -0400):
right, and thanks. '3a' is exactly what I am trying to test for - I am
posting another main topic to cover this


That's the sort of situations where a regular expression (used in
preg_match) is the easiest way:

/^[0-9]{1,2}[a-z]{1}$/ ---> 1 or 2 digits plus exactly 1 letter
/^[0-9]{1}[a-z]{0,2}$/ ---> exactly 1 digit plus 0, 1 or 2 letters

etc.

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la
intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: owyn | last post by:
Is there some way to convert a string which consists of a number(eg. 24) to an integer type? I am trying to get the value from the text property of a text box.
3
by: raulavi | last post by:
Can an EXE return Strings ? or exceptions? How? (I see so far that integers is the only thing to return).
4
by: sang | last post by:
I am trying to get the number that are present in the input string by using the isNumber(), but i have no idea about that any one help me. input for the program is "java123" output is only "123"...
1
by: haelly | last post by:
write a program that prompts the user to enter three different positive integer values.If the values are not different, the program prints a message"equal value" and terminates(hint:use the return...
3
shek124
by: shek124 | last post by:
i have a text box on my form. i want to insert the value from the textbox to database.. im the beginner of vb.net .. plz help me .. thanks in advance..
3
by: bfmccarthy1 | last post by:
Can anybody help me with writing this program? I do not know what function to use? 1. Prompt the user for a positive integer. 2. Print the numbers from zero to that number in the web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.