Almost.  But since this is not horseshoes nor hand grenades...

Here is a trap for A/N characters:

if (eregi("^[a-zA-Z0-9]+$",$GP[sifre])) {

corrections to your code:

Move the carat to the outside of the bracket -- I think the carat inside the
bracket means negation (I think). You want a starting character anchor so
that your code translates to "start with any of the following".

Add the plus sign after the brackets -- means "one or more of the preceding
characters"

Add the $ after the + sign  -- means "only the preceding character can be at
the end of the line."  Without the $ as an end anchor the user would be able
to put non-A/N characters at the end of the line of A/N characters and your
code would not trap it.

Mark Cain


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <php-db@lists.php.net>
Sent: Sunday, April 03, 2005 11:18 AM
Subject: [PHP-DB] eregi problem


> I m trying to check $GP[sifre] variable, $GP[sifre] must consist of alpha
> numeric chars only. here, how I check the variable:
>
> if((eregi("[^a-zA-Z0-9]",$GP[sifre])
>     echo 'true';
> else
>     echo 'false';
>
> It works if variable starts with alphabetic chars only.
> for example this returns 'ok'
>     $GP[sifre]='blabla234243';
> but this does not work: (if variable starts with numeric chars)
>     $GP[sifre]='3243242blabla';
>
> second one returns false, couldnt figure out the problem here. any help ?
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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

Reply via email to