diff --git a/formwork/fields/color.php b/formwork/fields/color.php index 67bee5935..aac4165ef 100644 --- a/formwork/fields/color.php +++ b/formwork/fields/color.php @@ -9,7 +9,7 @@ return [ 'methods' => [ 'validate' => function (Field $field, $value): string { - if (!Constraint::matchesRegex($value, '/^#[0-9A-Fa-f]{6}$/')) { + if (!Constraint::matchesRegex($value, '#[0-9A-Fa-f]{6}')) { throw new ValidationException(sprintf('Invalid value for field "%s" of type "%s"', $field->name(), $field->type())); } diff --git a/formwork/schemes/config/system.yaml b/formwork/schemes/config/system.yaml index 52881f397..6c41dd718 100644 --- a/formwork/schemes/config/system.yaml +++ b/formwork/schemes/config/system.yaml @@ -81,7 +81,7 @@ fields: label: '{{panel.options.system.files.allowedExtensions}}' icon: file-exclamation placeholder: '{{panel.options.system.files.allowedExtensions.noExtensions}}' - pattern: '^\.[a-zA-Z0-9]+$' + pattern: '\.[a-zA-Z0-9]+' options@: mimeTypes.getExtensionTypes() cache.enabled: diff --git a/formwork/src/Utils/Constraint.php b/formwork/src/Utils/Constraint.php index 736a6dc26..9319bddb0 100644 --- a/formwork/src/Utils/Constraint.php +++ b/formwork/src/Utils/Constraint.php @@ -64,8 +64,11 @@ public static function isEqualTo(mixed $value, mixed $comparison, bool $strict = /** * Return whether a value matches the specified regex pattern */ - public static function matchesRegex(string $value, string $regex): bool + public static function matchesRegex(string $value, string $regex, bool $entireMatch = true): bool { + if ($entireMatch) { + $regex = '^(?:' . trim($regex, '^$/') . ')$'; + } return (bool) @preg_match(Str::wrap($regex, '/'), $value); } diff --git a/panel/modals/newPage.yaml b/panel/modals/newPage.yaml index 6e55a4881..21b9bca65 100644 --- a/panel/modals/newPage.yaml +++ b/panel/modals/newPage.yaml @@ -13,7 +13,7 @@ fields: label: '{{page.slug}}' suggestion: '{{page.slug.suggestion}}' required: true - pattern: '^[a-z0-9\-]+$' + pattern: '[a-z0-9\-]+' source: title root: parent diff --git a/site/schemes/config/site.yaml b/site/schemes/config/site.yaml index a5e2a1c64..d57dbb86e 100644 --- a/site/schemes/config/site.yaml +++ b/site/schemes/config/site.yaml @@ -54,7 +54,7 @@ fields: label: '{{panel.site.languages.availableLanguages}}' icon: translate placeholder: '{{panel.site.languages.availableLanguages.noLanguages}}' - pattern: '^[a-z]{2,3}$' + pattern: '[a-z]{2,3}' translate: [label, placeholder] options@: languages.names