From a955b94f9224b6fd79027f9d8408cfae95709d9f Mon Sep 17 00:00:00 2001 From: Lasse Lehtinen Date: Fri, 8 Dec 2023 11:54:35 +0200 Subject: [PATCH] Added GS1 prefix check for ISBN's --- src/Rules/Isbn.php | 2 +- tests/Rules/IsbnTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Rules/Isbn.php b/src/Rules/Isbn.php index aca9485..7e32a06 100644 --- a/src/Rules/Isbn.php +++ b/src/Rules/Isbn.php @@ -37,7 +37,7 @@ public function passes($attribute, $value) return $this->shortChecksumMatches($value); case 13: - return parent::checksumMatches($value); // isbn-13 is a subset of ean-13 + return preg_match("/^(978|979)/", $value) && parent::checksumMatches($value); // isbn-13 is a subset of ean-13 } return false; diff --git a/tests/Rules/IsbnTest.php b/tests/Rules/IsbnTest.php index d220dad..cbb7364 100644 --- a/tests/Rules/IsbnTest.php +++ b/tests/Rules/IsbnTest.php @@ -69,6 +69,7 @@ public function dataProvider() [false, 'ABC'], [false, '978-0-306-40615-6'], [false, '99921-58-10-6'], + [false, '0123456789012'], ]; } @@ -122,6 +123,7 @@ public function dataProviderLong() [false, 'ABC'], [false, '978-0-306-40615-6'], [false, '99921-58-10-6'], + [false, '0123456789012'], ]; } -} +} \ No newline at end of file