Assert\Assertion::alnum PHP Method

alnum() public static method

Assert that value is alphanumeric.
public static alnum ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
    public static function alnum($value, $message = null, $propertyPath = null)
    {
        try {
            static::regex($value, '(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath);
        } catch (AssertionFailedException $e) {
            $message = sprintf($message ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_ALNUM, $propertyPath);
        }
        return true;
    }

Usage Example

Ejemplo n.º 1
0
 public function testInvalidAlnum()
 {
     $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_ALNUM);
     Assertion::alnum("1a");
 }