1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00
appwrite/src/Appwrite/Storage/Validator/FileName.php
2020-10-27 21:44:15 +02:00

38 lines
649 B
PHP

<?php
namespace Appwrite\Storage\Validator;
use Utopia\Validator;
class FileName extends Validator
{
public function getDescription()
{
return 'Filename is not valid';
}
/**
* The file name can only contain "a-z", "A-Z", "0-9" and "-" and not empty.
*
* @param mixed $name
*
* @return bool
*/
public function isValid($name)
{
if (empty($name)) {
return false;
}
if (!is_string($name)) {
return false;
}
if (!\preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
return false;
}
return true;
}
}