Skip to content

Validator Constraints#

Info

All validators are available as PHP 8 attributes since version 3.1.1.

PasswordStrength#

The PasswordStrengthChecker is based on a snipped provided in Symfony 1.

Usage

use Leapt\CoreBundle\Validator\Constraints as LeaptAssert;

#[LeaptAssert\PasswordStrength(min: 6, max: 72, score: 80')]
public string $plainPassword;
use Leapt\CoreBundle\Validator\Constraints as LeaptAssert;

/**
 * @LeaptAssert\PasswordStrength(min=6, max=72, score=80)
 */
public string $plainPassword;
Options
Name Description Default value
min Minimum length for the password. null
max Maximum length for the password. null
score Required strength to pass validation, between 0 and 100. 50
minMessage Message shown if the password is too short. This password is too short. It should have {{ limit }} characters or more.
maxMessage Message shown if the password is too long. This password is too long. It should have {{ limit }} characters or less.
scoreMessage Message shown if the password is not strong enough. This password is not strong enough.

Recaptcha#

This validator should be used with the Recaptcha Type, and is based on the EWZRecaptchaBundle.

Usage

use Leapt\CoreBundle\Validator\Constraints as LeaptAssert;

#[LeaptAssert\Recaptcha(message: 'Invalid captcha.')]
public $recaptcha;
use Leapt\CoreBundle\Validator\Constraints as LeaptAssert;

/**
 * @LeaptAssert\Recaptcha(message="Invalid captcha.")
 */
public $recaptcha;
Options
Name Description Default value
message Message shown if the captcha is not valid. This value is not a valid captcha.
invalidHostMessage Message shown if the host is not valid. The captcha was not resolved on the right domain.

See also RecaptchaType.

Slug#

Helps to validate that the provided value matches a valid slug format.

Usage

use Leapt\CoreBundle\Validator\Constraints as LeaptAssert;

#[LeaptAssert\Slug]
public string $slug;
use Leapt\CoreBundle\Validator\Constraints as LeaptAssert;

/**
 * @LeaptAssert\Slug()
 */
public string $slug;
Options
Name Description Default value
message Message shown if the slug is not valid. A slug can only contain lowercase letters, numbers and hyphens.
pattern Pattern used to check the slug format. /^([a-z0-9-]+)$/