Skip to content

Commit

Permalink
Allow numbers at the start of field handles
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Aug 19, 2024
1 parent 3db6fae commit ffc7f4a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Rules/Handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Handle implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! preg_match('/^[a-zA-Z][a-zA-Z0-9]*(?:_{0,1}[a-zA-Z0-9])*$/', $value)) {
if (! preg_match('/^[a-zA-Z0-9][a-zA-Z0-9]*(?:_{0,1}[a-zA-Z0-9])*$/', $value)) {
$fail('statamic::validation.handle')->translate();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/HandleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function it_validates_handles()
$this->assertPasses('foo123');
$this->assertPasses('foo123_20bar');
$this->assertPasses('FooBar');
$this->assertPasses('1foo');

$this->assertFails('foo-bar');
$this->assertFails('_foo');
Expand All @@ -31,7 +32,6 @@ public function it_validates_handles()
$this->assertFails('foo_bar_');
$this->assertFails('foo__bar');
$this->assertFails('foo___bar');
$this->assertFails('1foo');
$this->assertFails('*foo');
$this->assertFails('foo#');
$this->assertFails('foo_!bar');
Expand Down

0 comments on commit ffc7f4a

Please sign in to comment.