diff --git a/src/Json/Validator.php b/src/Json/Validator.php index b9b249d..2b44cd6 100644 --- a/src/Json/Validator.php +++ b/src/Json/Validator.php @@ -500,7 +500,7 @@ protected function checkExclusiveMaximum($entity, $schema, $entityName) protected function checkPattern($entity, $schema, $entityName) { if (isset($schema->pattern) && $schema->pattern) { - if (!preg_match($schema->pattern, $entity)) { + if (!preg_match('/' . $schema->pattern . '/', $entity)) { throw new ValidationException(sprintf('String does not match pattern for [%s]', $entityName)); } } @@ -756,4 +756,4 @@ protected function checkDivisibleBy($entity, $schema, $entityName) return $this; } -} \ No newline at end of file +} diff --git a/tests/mock/pattern.json b/tests/mock/pattern.json index 81a65a0..ff0cede 100644 --- a/tests/mock/pattern.json +++ b/tests/mock/pattern.json @@ -1,4 +1,4 @@ { "type" : "string", - "pattern" : "/^[A-Z]+$/" -} \ No newline at end of file + "pattern" : "^[A-Z]+$" +}