Jump to content

[SOLVED] checking file name


ballouta

Recommended Posts

You could use the following code to determine they have a valid filename:

 

if (!preg_match('/[\d]{15}\.ask/', $_FILES['input_name']['name']))
{
    // invalid
}
else
{
    // valid
}

 

Not tested but should work no problems. I'm assuming you know how to do the rest?

\d does not need to be wrapped in brackets because it is itself a shorthand character class.  But you don't really want to use it anyways, as \d accepts more than strictly 0-9.  Better to explicitly use 0-9.  Also your original regex probably wasn't working due to you not anchoring boundaries to it.  You kind of fixed it by adding word boundary shorthands to it but that just stops someone from entering in "blah232343..." not "blah 234324..." or "blah@234324..." etc... also you put the 2nd one in the wrong place.  The anchors you really want are the start and end of line anchors ^...$

 

/^[0-9]{15}\.ask$/

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.