Skip to content

Commit d1011e3

Browse files
support for incasesensitive patterns
Schema: { "firstname": { "type": "string", "pattern": "alan", "inCaseSensitive": true } } will use -i modifier on preg_match and match with Alan, ALAN, aLaN, etc.
1 parent 325a0f8 commit d1011e3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/JsonSchema/Constraints/StringConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function check($element, $schema = null, JsonPointer $path = null, $i = n
3939
}
4040

4141
// Verify a regex pattern
42-
if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u', $element)) {
42+
if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u'.($schema->inCaseSensitive?'i':''), $element)) {
4343
$this->addError($path, "Does not match the regex pattern " . $schema->pattern, 'pattern', array(
4444
'pattern' => $schema->pattern,
4545
));

0 commit comments

Comments
 (0)