[PHP] ereg function

2004-12-31 Thread Michael Lutaaya
I want to validate someones age. How do I do this in
the ereg function.

I also have some visitors on my site who are in
between the ages of 7-9 so don't forget to make them
part of the ereg function.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ereg function

2004-12-31 Thread Rasmus Lerdorf
Numbers are pretty easy.  You could just do:

   $age = (int)$_POST['age'];
   if($age  9) do_something();
   else do_something_else();

Using ereg doesn't make much sense in this case.

-Rasmus

On Fri, 31 Dec 2004, Michael Lutaaya wrote:

 I want to validate someones age. How do I do this in
 the ereg function.

 I also have some visitors on my site who are in
 between the ages of 7-9 so don't forget to make them
 part of the ereg function.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ereg function

2004-12-31 Thread Rory Browne
The ereg function doesn't have the capability to test the age of the
person viewing your page. You have to depend on them to input their
age in some way.

Your answer depends on how your age is submitted. Assuming it is
submited as $_POST['age'], you could perhaps use ereg(0*[7-9]$,
$_POST['age']) - that might work but I haven't used ereg - ever, I
perfer to use the faster PCRE regex functions, such as
preg_match(/^0*[7-9]$/, $_POST['age']); which will match any amount
of zeros, followed by anything between 7 and 9, ie 8,
008, or 08

Having all that said, I wouldn't use reges for smething like this.

On Fri, 31 Dec 2004 15:46:46 -0500 (EST), Michael Lutaaya
[EMAIL PROTECTED] wrote:
 I want to validate someones age. How do I do this in
 the ereg function.
 
 I also have some visitors on my site who are in
 between the ages of 7-9 so don't forget to make them
 part of the ereg function.
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] ereg function

2001-05-24 Thread Jay Paulson

hello-
I have a pretty easy question for some of you.  I'm using the ereg function and it's 
not returning a true or false after it runs.  Below is the code snippet I'm using.

echo ereg(^[a-zA-Z]$, $fname);

as you can see I'm just looking to make sure the variable $fname just has characters 
a-zA-Z and nothing else.  Anyway, I'm running PHP 4.0.5 and I'm using the ereg 
function else where and it seems to work fine.

Thanks,
Jay Paulson



Re: [PHP] ereg function

2001-05-24 Thread CC Zona

In article 002e01c0e46c$ec2459a0$6e00a8c0@webdesign,
 [EMAIL PROTECTED] (Jay Paulson) wrote:

 echo ereg(^[a-zA-Z]$, $fname);
 
 as you can see I'm just looking to make sure the variable $fname just has 
 characters a-zA-Z and nothing else.

Actually, you're checking whethere the variable is a single-character 
string a-zA-Z.  For what you want:

ereg(^[a-zA-Z]+$, $fname); //add plus sign

Note also that although the docs imply that ereg() returns an integer 
value, it says further down Returns true if a match for pattern was found 
in string, or false if no matches were found or an error occurred.  In my 
experience, boolean values don't echo well.  Try this instead:

if(ereg(^[a-zA-Z]+$, $fname))
   {
   echo pPassed!/p\n;
   }
 else
   {
   echo pFailed.  Enter a different value./p\n;
   }

-- 
CC

-- 
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]