Skip to content

Commit 17cff6e

Browse files
committed
refined regex check and removed redundant ones
1 parent 3f576ed commit 17cff6e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/Traits/ErrorTrait.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,8 @@ private static function assertValidName(string $name): void
111111
throw new InvalidArgumentException("A name cannot be an empty string");
112112
}
113113

114-
if (!preg_match('/^\p{L}[\p{L}0-9_]*$/u', $name)) {
115-
throw new InvalidArgumentException('A name can only contain alphanumeric characters and underscores');
116-
}
117-
118-
if (is_numeric($name[0])) {
119-
throw new InvalidArgumentException('A name cannot begin with a numeric character');
114+
if (!preg_match('/^\p{L}[\p{L}\d_]*$/u', $name)) {
115+
throw new InvalidArgumentException('A name can only contain alphanumeric characters and underscores and must begin with an alphanumeric character');
120116
}
121117

122118
if (strlen($name) >= 65535) {

0 commit comments

Comments
 (0)