I am trying to use th MinLength validator in my symfony project.
Here is how I am using it:
use Symfony\Component\Validator\Constraints\MinLength;
class RegisterNewUser
{
    protected $password;
    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        if( isset( $metadata->properties["password"] ) ) 
            unset($metadata->properties["password"]);
        $password_blank  = new NotBlank();
        $password_min       = new MinLength(5);
        $password_blank->message    = "The password should not be blank";
        $password_min->message     = "The password is too short. It should have {{ limit }} characters or more";
        $metadata->addPropertyConstraint('password', $password_blank);
        $metadata->addPropertyConstraint('password', $password_min );
    }
}
The Error message I am getting is:
FatalErrorException: Error: Class 'Symfony\Component\Validator\Constraints\MinLength' not found in...
I have found the solution:
From the Symfony documentation:
The MinLength constraint is deprecated since version 2.1 and will be removed in Symfony 2.3. Use Length with the min option instead.
So, the solution is:
use Symfony\Component\Validator\Constraints\Length;
....
$password_min           = new Length(array('min'=>5));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With