Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Ulid.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ class Ulid
* @param string $ulid
* @return bool
*/
public function isValidFormat(
string $ulid
): bool {
public function isValidFormat(string $ulid): bool
{
$validator = UlidConstants::TIME_LENGTH + UlidConstants::RANDOM_LENGTH;

if (strlen($ulid) !== $validator) {
return false;
}
return true;

return preg_match(
UlidConstants::REGEX,
$ulid
) === 1;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/UlidConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class UlidConstants
const TIME_MAX = 281474976710655;
const TIME_LENGTH = 10;
const RANDOM_LENGTH = 16;
const REGEX = '/^[0-9A-HJKMNP-TV-Z]{26}$/ ';
}
12 changes: 12 additions & 0 deletions tests/UlidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ public function testDecodeTimeInvalidTime()
$ulid->decodeTime('QS234SAD23RADSWRA3FADQ3RS2');
}

/**
* @covers Ulid\Ulid::isValidFormat
*/
public function testIsValidFormatDoesNotValidateCharacters()
{
$ulid = new Ulid();

$result = $ulid->isValidFormat('01E475VQGHNW990PVHXFDT4C6W');

$this->assertTrue($result);
}

protected function tearDown(): void
{
//
Expand Down