SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Check Filenames

Hybrid View

  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    How do I check a filename for certain type of characters? like...i want to disallow any file that has #, &, + etc in the filename. how do I do that?

    Or simpler said, How do i allow a filename that only consists of letters and numbers?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could use regex to allow only acceptable characters, eg, [a-zA-Z0-9]* would allow zero or more letters (lower or upper case) or numbers. Actually, you could use eregi, and that would make it case-insensitive, so you wouldn't need to specify A-Z too.

    for example:

    if ( eregi("^[_a-z0-9]+$", $FName) )
    {
    echo "filename has one or more valid characters (_, 0-9, a-z).\n";
    }
    Last edited by cokeman; May 2, 2001 at 07:35.

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help cokeman!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •