This is a discussion on Matching a filename within the PHP Language forums, part of the PHP Programming Forums category; I wanna match the incorrect filename with the next regular expression but it doesnīt work. Why? I donīt ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I wanna match the incorrect filename with the next regular expression
but it doesnīt work. Why? I donīt know. if (ereg("[^A-Za-z0-9\.]+", $str)) return false; else return true; I wanna allow only letters (A-Za-z) and numbers (0-9) and of course a dot for the extension. Have anybody any suggestion or idea? Any idea would be appreciated!! Fran García |
|
|||
|
On 2005-02-25, Fran Garcia <fgarcia@ua.es> wrote:
> I wanna match the incorrect filename with the next regular expression > but it doesnīt work. Why? I donīt know. > > if (ereg("[^A-Za-z0-9\.]+", $str)) > return false; > else > return true; return preg_match("#^[A-Za-z0-9\.]+$#", $str) but what about $string = "C:\\My Documents" ? -- Met vriendelijke groeten, Tim Van Wassenhove <http://www.timvw.info> |
|
|||
|
"Tim Van Wassenhove" <timvw@users.sourceforge.net> wrote in message
news:3891bhF5kv67lU1@individual.net... > On 2005-02-25, Fran Garcia <fgarcia@ua.es> wrote: > > I wanna match the incorrect filename with the next regular expression > > but it doesnīt work. Why? I donīt know. > > > > if (ereg("[^A-Za-z0-9\.]+", $str)) > > return false; > > else > > return true; > > return preg_match("#^[A-Za-z0-9\.]+$#", $str) > > but what about $string = "C:\\My Documents" ? preg_match('/^[\w\.]+$/', $str) is more compact; covers the underscore as well. |