RE: [PHP] Checking for Valid Charactors.

2003-06-08 Thread John W. Holmes
> From: Jason Wong [mailto:[EMAIL PROTECTED]
> > On Sunday 08 June 2003 16:22, Philip J. Newman wrote:
> > I would liek to check for 0-9 and . charactors i'm using ...
> >
> > $email = "60.00";
> >
> > if eregi("^[0-9.])?$",$email) {
> >
> > echo"valid";
> >
> > } else {
> >
> > echo"not valid";
> >
> > }
> >
> > Its not working well. umm ... help ...
> 
>   eregi("^([0-9.])*$", $string)
> 
> will match:
>   an empty string
>   a string containing only 0-9 and periods
> 
> It is better for you to learn the preg_*() functions instead of the
> ereg*()
> ones.

FYI, that code will also allow a string such as "99.4.3223...04..."

If that's not desirable, you could look into using the is_float() or
is_numeric() functions, or a regex such as:

if(preg_match('/^[0-9]*\.?[0-9]+$/',$string))
{ echo "good"; }
else
{ echo "bad"; }

That will allow text/numbers with or without a period. 

---John W. Holmes...

Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



Re: [PHP] Checking for Valid Charactors.

2003-06-08 Thread Philip J. Newman
thanks

- Original Message -
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 08, 2003 8:57 PM
Subject: Re: [PHP] Checking for Valid Charactors.


> On Sunday 08 June 2003 16:22, Philip J. Newman wrote:
> > I would liek to check for 0-9 and . charactors i'm using ...
> >
> > $email = "60.00";
> >
> > if eregi("^[0-9.])?$",$email) {
> >
> > echo"valid";
> >
> > } else {
> >
> > echo"not valid";
> >
> > }
> >
> > Its not working well. umm ... help ...
>
>   eregi("^([0-9.])*$", $string)
>
> will match:
>   an empty string
>   a string containing only 0-9 and periods
>
> It is better for you to learn the preg_*() functions instead of the
ereg*()
> ones.
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> --
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> --
> /*
> This fortune is false.
> */
>
>
> --
> 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] Checking for Valid Charactors.

2003-06-08 Thread Jason Wong
On Sunday 08 June 2003 16:22, Philip J. Newman wrote:
> I would liek to check for 0-9 and . charactors i'm using ...
>
> $email = "60.00";
>
> if eregi("^[0-9.])?$",$email) {
>
> echo"valid";
>
> } else {
>
> echo"not valid";
>
> }
>
> Its not working well. umm ... help ...

  eregi("^([0-9.])*$", $string)

will match:
  an empty string
  a string containing only 0-9 and periods

It is better for you to learn the preg_*() functions instead of the ereg*() 
ones.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
This fortune is false.
*/


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



[PHP] Checking for Valid Charactors.

2003-06-08 Thread Philip J. Newman
I would liek to check for 0-9 and . charactors i'm using ...

$email = "60.00";

if eregi("^[0-9.])?$",$email) {

echo"valid";

} else {

echo"not valid";

}

Its not working well. umm ... help ...