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?
| SitePoint Sponsor |





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

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 08:35.





Thanks for your help cokeman!
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
Bookmarks