在Symfony2
Framework中提交表单时,我尝试使用正则表达式验证电子邮件地址。我checkMX and checkHost
在Entity
课堂上使用属性。完成了 但是我无法验证它的正则表达式,即 {,$,#,!,^
..请帮助某人...这是我的代码段..
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* product1
*/
class product1
{
/**
* @var int
*/
private $id;
/**
* @var string
* @Assert\Email(
*
* checkHost= true,
* checkMX = true,
* message="Invalid email host"
*
*
* )
* @Assert\Email(
* strict=false,
* message="invalid"
* )
*
*/
private $email;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set email
*
* @param string $email
*
* @return product1
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
}
根据文档,您可以使用以下注释:
/**
* @Assert\Regex(
* pattern="/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/",
* message="not_valid_email"
* )
*
* @var string
*/
private $email;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句