Form- Basic Constraints – Symfony2

usa:

use SymfonyComponentValidatorConstraintsBlank;
use SymfonyComponentValidatorConstraintsNotBlank;
use SymfonyComponentValidatorConstraintsFile;
use SymfonyComponentValidatorConstraintsNotNull;
use SymfonyComponentValidatorConstraintsNull;
use SymfonyComponentValidatorConstraintsTrue;
use SymfonyComponentValidatorConstraintsFalse;
use SymfonyComponentValidatorConstraintsType;

… class UserType ..
… public function buildForm (…

$builder->add('name', 'text', array(
'label' => 'Name',
// css
'attr' => array(
'class' => 'someclass',
'id' => 'someID'
),
'constraints' => array(

new Blank(array(
'message' => 'This value should be blank.')
),
new NotBlank(array(
'message' => 'This value should not be blank.')
),
new NotNull(array(
'message' => 'This value should not be null.')
),
new Null(array(
'message' => 'This value should be null.')
),
new True(array(
'message' => 'This value should be true.')
),
new False(array(
'message' => 'This value should be false.')
),
new Type(array(
'message' => 'This value should be of type {{ type }}.',
'type' => 'float ') // * see Type
),
),
)
);