I need to make some regex pattern form url which have 4 patterns:
https://www.example.com
http://www.example.com
https://example.com
http://example.com
I need it for symfony 2 assert so it should be one string.
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('url', UrlType::class, array(
'label' => false,
'constraints' => array(
new NotBlank(array(
'message' => "Url nie może być pusty"
)),
new Regex(array(
'pattern' => '/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/',
'match' => true,
'message' => 'Podany url jest nieprawidłowy.'
)))
)
);
}
Anyone can help me?
Aucun commentaire:
Enregistrer un commentaire