PHP integer form validation

This is a discussion on "PHP integer form validation" within the PHP Forum section. This forum, and the thread "PHP integer form validation are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 23rd, 2008, 20:38
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
PHP integer form validation

I'm making a couple of validations for a form. One of them checks to see if the number is an integer. I figured I can just use isint(). Wrong. Since the POST data from the form is a string, isint won't work. And isnumerical() will return yes if it has a decimal point (float) but I don't want that. So how do I check to make sure a number string is an int and not a float?
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote

  #2 (permalink)  
Old Feb 24th, 2008, 06:18
Junior Member
Join Date: Feb 2008
Location: Poreč
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP integer form validation

One of the many possible solutions:

if( preg_match( '/^\d+$/', $yourStringVar ) ) { ... }
Reply With Quote
  #3 (permalink)  
Old Feb 24th, 2008, 17:18
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: PHP integer form validation

or ctype_digit()
Reply With Quote
  #4 (permalink)  
Old Feb 24th, 2008, 20:09
Junior Member
Join Date: Feb 2008
Location: Glasgow
Age: 28
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP integer form validation

If you add 0 then try isint() then you should be fine.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form validation help! psycho wolvesbane JavaScript Forum 16 Feb 12th, 2008 16:40
Form Validation cjrollo Flash & Multimedia Forum 0 Feb 22nd, 2007 17:33
PHP Form Validation ??? j4mes_bond25 PHP Forum 2 May 31st, 2006 23:08
Form Validation Help gajlehab PHP Forum 7 Dec 13th, 2005 19:40
Form validation brittny JavaScript Forum 2 Jul 8th, 2005 19:46


All times are GMT. The time now is 02:11.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43