RE: [PHP] simple form validation

From: Date: Thu, 26 Apr 2001 15:26:31 +0000
Subject: RE: [PHP] simple form validation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-50470@lists.php.net to get a copy of this message
you can do either: ereg: if(isset($field) and !$field!='') { // first check if it was submitted at all, // you'll get errors if it isn't there $res = False; $field = trim($field); // trim it to remove any whitespaces // way 1, ereg: if(ereg("^[[:digit:]]$", $field)) { $res = True; } // way 2, is_numeric() (the best, fastest way): if(is_numeric($field)) { $res = True; } // way 3, is_int() (the same): if(is_int($field)) { $res = True; } // way 4, is_num() (the same): if(is_int($field)) { $res = True; } // way 5, gettype() (the same): if(gettype($field)=='integer') { $res = True; } // way 6, a stupi one but works if($field>0) { $res = True; } } as you can see there are several ways to do it. use wchich suits you better. In fact I would rather use JavaScript in form, and here. my favorite? is_int(). shorter to type :-) Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) maxim@phpbeginner.com www.phpbeginner.com -----Original Message----- From: Jamie Saunders [mailto:webprogramming@jamie-s.co.uk] Sent: Friday, April 27, 2001 11:39 PM To: php-general@lists.php.net Subject: [PHP] simple form validation Hi, First of all, I've just joined this list, so here's a brief introduction. My name's Jamie Saunders, I'm an 18 year old student from the UK studying for my A-Levels. I'm currently working on a Computer Studies project for a local business which involves setting up several databases on the web. After reading Webmonkey.com's excellent introduction to PHP I've decided to use it in conjunction with MySQL for the project. Later this year, if all goes well I'm hoping to take a 3 years BA Honors course in Multimedia Web Production. Right, you still with me? What I'd like to know is how to validate a text field in an HTML form to make sure it only contains numbers. I know how to check it so it only contains letters, but not numbers - the field I want to check is for phone numbers - so it can't contain any special characters either. I expect this is very simple but I can't seem to get it working properly. Any help appreciated. Cheers, Jamie Saunders -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#50470) next »