I want to define email validator with annotation, like this
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ODM\Document(collection="dummies")
*/
class Dummy
{
/** @ODM\Id */
private $id;
/** @ODM\String @Assert\Email() */
private $email;
}
Doctrine explains reasons for not including validators here
Symfony has a nice form validator built in.
You could also construct a callback
/**
* @Entity
* @HasLifecycleCallbacks
*/
/**
* @PrePersist @PreUpdate
*/
public function validateEmail() {
//validation
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.