1
0
Fork 0
mirror of synced 2024-09-30 09:18:14 +13:00
appwrite/src/Appwrite/Database/Validator/Key.php

52 lines
917 B
PHP
Raw Normal View History

2019-05-09 18:54:39 +12:00
<?php
namespace Appwrite\Database\Validator;
2019-05-09 18:54:39 +12:00
use Utopia\Validator;
class Key extends Validator
{
/**
* @var string
*/
protected $message = 'Parameter must contain only letters with no spaces or special chars and be shorter than 32 chars';
/**
* Get Description.
2019-05-09 18:54:39 +12:00
*
* Returns validator description
*
* @return string
*/
public function getDescription()
{
return $this->message;
}
/**
* Is valid.
2019-05-09 18:54:39 +12:00
*
* Returns true if valid or false if not.
*
* @param $value
*
2019-05-09 18:54:39 +12:00
* @return bool
*/
public function isValid($value)
{
2020-06-25 09:02:27 +12:00
if (!\is_string($value)) {
2020-06-11 09:42:16 +12:00
return false;
}
if (\preg_match('/[^A-Za-z0-9\-\_]/', $value)) {
2019-05-09 18:54:39 +12:00
return false;
}
if (\mb_strlen($value) > 32) {
2019-05-09 18:54:39 +12:00
return false;
}
return true;
}
}