[PHP] simple form validation

2001-04-26 Thread Jamie Saunders

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] simple form validation

2001-04-26 Thread Pavel Jartsev

Jamie Saunders wrote:
 
 ...
 
 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.  
 
 ...
 

Try this:
?
$phone_nr = '54256009';
if ( ereg( '^[0-9]+$', $phone_nr )) 
...ok...
else
...not ok...

?

Hope this helps.

-- 
Pavel a.k.a. Papi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] simple form validation

2001-04-26 Thread PHPBeginner.com

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($field0) { $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)
 [EMAIL PROTECTED]
 www.phpbeginner.com





-Original Message-
From: Jamie Saunders [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 27, 2001 11:39 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]