for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of Dimtrovich/Validation.
*
* (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Dimtrovich\Validation\Rules;
class Username extends AbstractRule
{
* Check if the given value is a valid username
* Pattern for "valid" username
* - only alpha-numeric (a-z, A-Z, 0-9), underscore and minus
* - starts with an letter (alpha)
* - underscores and minus are not allowed at the beginning or end
* - multiple underscores and minus are not allowed (-- or _____)
* @credit <a href="https://github.com/Intervention/validation">Intervention/validation - \Intervention\Validation\Rules\Username</a>
* @param mixed $value
public function check($value): bool
return preg_match('/^[a-z][a-z0-9]*(?:[_\-][a-z0-9]+)*$/i', $value);
return preg_match('/^[a-...a-z0-9]+)*$/i', $value)
integer
boolean
}