{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/14943","labels_url":"https://api.github.com/repos/symfony/symfony/issues/14943/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/14943/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/14943/events","html_url":"https://github.com/symfony/symfony/issues/14943","id":87297159,"number":14943,"title":"Regex validator throws exception on invalid input","user":{"login":"emil-nasso","id":1119706,"avatar_url":"https://avatars.githubusercontent.com/u/1119706?v=3","gravatar_id":"","url":"https://api.github.com/users/emil-nasso","html_url":"https://github.com/emil-nasso","followers_url":"https://api.github.com/users/emil-nasso/followers","following_url":"https://api.github.com/users/emil-nasso/following{/other_user}","gists_url":"https://api.github.com/users/emil-nasso/gists{/gist_id}","starred_url":"https://api.github.com/users/emil-nasso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emil-nasso/subscriptions","organizations_url":"https://api.github.com/users/emil-nasso/orgs","repos_url":"https://api.github.com/users/emil-nasso/repos","events_url":"https://api.github.com/users/emil-nasso/events{/privacy}","received_events_url":"https://api.github.com/users/emil-nasso/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-11T10:33:25Z","updated_at":"2015-06-11T10:43:34Z","closed_at":null,"body":"I have this example, which i use in a small json-api where i use the form component to handle requests and validation.\r\n\r\n```php\r\n->add('account', 'text', [\r\n                'constraints' => [\r\n                    new NotBlank(),\r\n                    new Type('string'),\r\n                    new Regex(\"/^XX\\d+$/i\")\r\n                ]\r\n            ])\r\n```\r\n\r\nI have a form field for an accountname. The format of this name is `XX1234`. \r\n\r\nThe validation above works great if the data being validated is a string. If i pass in an array instead of the string i will get an exception that is originating from here: \r\n\r\nhttps://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Validator/Constraints/RegexValidator.php#L43\r\n\r\nIn my opinion the validation should just fail here instead of throwing an exception. I pass an array in, and try to run an regexp on it. It seems obvious to me that something is wrong with the input data then and the validation should fail.\r\n\r\nOther validation constraints seems to work this way. Look at this example:\r\n\r\n```php\r\n->add('disksize', 'text', [\r\n                'constraints' => [\r\n                    new NotBlank(),\r\n                    new Type('numeric'),\r\n                    new Range(['min' => 10, 'max' => 200])\r\n                ]\r\n            ])\r\n```\r\n\r\nThis works. I get an validation error and no exceptions. Other validations contraints, like `Length` seems to have the same problem as `Regex`\r\n\r\nI think it would be great if all constraints just failed if they were passed an array if they cant handle an array. Or is there something i am overseeing?\r\n\r\nIs there some way i can work around this to make it fail validation if i pass in an array?\r\n"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/111082674","html_url":"https://github.com/symfony/symfony/issues/14943#issuecomment-111082674","issue_url":"https://api.github.com/repos/symfony/symfony/issues/14943","id":111082674,"user":{"login":"Tobion","id":610090,"avatar_url":"https://avatars.githubusercontent.com/u/610090?v=3","gravatar_id":"","url":"https://api.github.com/users/Tobion","html_url":"https://github.com/Tobion","followers_url":"https://api.github.com/users/Tobion/followers","following_url":"https://api.github.com/users/Tobion/following{/other_user}","gists_url":"https://api.github.com/users/Tobion/gists{/gist_id}","starred_url":"https://api.github.com/users/Tobion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tobion/subscriptions","organizations_url":"https://api.github.com/users/Tobion/orgs","repos_url":"https://api.github.com/users/Tobion/repos","events_url":"https://api.github.com/users/Tobion/events{/privacy}","received_events_url":"https://api.github.com/users/Tobion/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T10:43:34Z","updated_at":"2015-06-11T10:43:34Z","body":"Ref. #5334, #4102, #13804 etc"}}