View Single Post
Old 10-01-2007, 03:05 PM   #3 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Code:
// Returns true if the extension is invalid
function checkFileExtentions(form)
{
	if (check_file_extentions == false)
	{
		return false;
	}
	
	// Regex of valid extensions
	var re = /\.(jpg|jpeg|png|gif|bmp)$/i
	
	// If we have a filename to check and it is invalid
	if (form['filename'].value != '' && !form['filename'].value.match(re))
	{
		var name = form['filename'].value;
		var ext  = name.substr(name.lastIndexOf('.')+1).toLowerCase();
		alert('Sorry, uploading a file with the extention "' + ext + '" is not allowed.');
		return true;
	}
	
	return false;
}
Salathe is offline  
Reply With Quote