mirror of
https://github.com/appwrite/appwrite
synced 2026-05-18 14:38:35 +00:00
34 lines
563 B
PHP
34 lines
563 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Storage\Validators;
|
||
|
|
|
||
|
|
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 string $name
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
public function isValid($name)
|
||
|
|
{
|
||
|
|
if(empty($name)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(!preg_match('/^[a-zA-Z0-9.]+$/', $name)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|