diff --git a/README.md b/README.md index 36aaf47..8393ebc 100755 --- a/README.md +++ b/README.md @@ -44,6 +44,13 @@ The following validation rules are currently available: | FileExists | validation.file_exists | Requires that the given value is a path to an existing file - see class for details | | Equals | validation.equals | Requires that the given value is equal to another given value | | MacAddress | validation.mac_address | Requires that the given value is a valid MAC address | +| ISBN | validation.isbn | Requires that the given value is a valid ISBN-10 or ISBN-13 number | +| EndsWith | validation.ends_with | Requires that the given value ends with a given string - see class for details | +| EvenNumber | validation.even_number | Requires that the given value is an even number (decimals are first converted using intval) | +| OddNumber | validation.odd_number | Requires that the given value is an odd number (decimals are first converted using intval) | +| Lowercase | validation.lowercase | Requires that the given value is lowercase string | +| Uppercase | validation.uppercase | Requires that the given value is uppercase string | +| Titlecase | validation.titlecase | Requires that the given value is titlecase string | The package will receive new rules over time, however since these updates will not be breaking changes, they will not receive major version numbers unless Laravel changes in such a way that the package requires a re-write. diff --git a/src/EndsWith.php b/src/EndsWith.php new file mode 100644 index 0000000..2ea8190 --- /dev/null +++ b/src/EndsWith.php @@ -0,0 +1,46 @@ +parameters[0]); + } + + + + /** + * Get the validation error message. + * + * @param none. + * @return string. + * + **/ + public function message() + { + return Helper::getLocalizedErrorMessage( + 'ends_with', + 'The :attribute must end with the text "' . $this->parameters[0] . '"' + ); + } + +} \ No newline at end of file diff --git a/src/EvenNumber.php b/src/EvenNumber.php new file mode 100644 index 0000000..589c512 --- /dev/null +++ b/src/EvenNumber.php @@ -0,0 +1,40 @@ + [new EndsWith('world')]]; + + // Execute the tests + $this->assertFalse(validator(['text' => 'hello'], $rule)->passes()); + $this->assertTrue(validator(['text' => 'hello world'], $rule)->passes()); + $this->assertFalse(validator(['text' => 'hello worldy'], $rule)->passes()); + } + +} \ No newline at end of file diff --git a/tests/EvenNumber.php b/tests/EvenNumber.php new file mode 100644 index 0000000..de7be5a --- /dev/null +++ b/tests/EvenNumber.php @@ -0,0 +1,27 @@ + [new EvenNumber]]; + + // Execute the tests + $this->assertFalse(validator(['number' => '1'], $rule)->passes()); + $this->assertTrue(validator(['number' => '2'], $rule)->passes()); + $this->assertFalse(validator(['number' => '3'], $rule)->passes()); + $this->assertTrue(validator(['number' => '4'], $rule)->passes()); + } + +} \ No newline at end of file diff --git a/tests/ISBNTest.php b/tests/ISBNTest.php new file mode 100644 index 0000000..b0308d5 --- /dev/null +++ b/tests/ISBNTest.php @@ -0,0 +1,32 @@ + [new ISBN]]; + + // Execute the tests + $this->assertFalse(validator(['book' => '1'], $rule)->passes()); + $this->assertFalse(validator(['book' => '1#'], $rule)->passes()); + $this->assertFalse(validator(['book' => 'a1#'], $rule)->passes()); + $this->assertTrue(validator(['book' => 'ISBN 978-0-596-52068-7'], $rule)->passes()); + $this->assertTrue(validator(['book' => 'ISBN-13: 978-0-596-52068-7'], $rule)->passes()); + $this->assertTrue(validator(['book' => '978 0 596 52068 7'], $rule)->passes()); + $this->assertTrue(validator(['book' => '9780596520687'], $rule)->passes()); + $this->assertTrue(validator(['book' => 'ISBN-10 0-596-52068-9'], $rule)->passes()); + $this->assertTrue(validator(['book' => '0-596-52068-9'], $rule)->passes()); + } + +} \ No newline at end of file diff --git a/tests/LowercaseTest.php b/tests/LowercaseTest.php new file mode 100644 index 0000000..fa9d45d --- /dev/null +++ b/tests/LowercaseTest.php @@ -0,0 +1,25 @@ + [new Lowercase]]; + + // Execute the tests + $this->assertTrue(validator(['text' => 'hello'], $rule)->passes()); + $this->assertFalse(validator(['text' => 'HELLO'], $rule)->passes()); + } + +} \ No newline at end of file diff --git a/tests/OddNumberTest.php b/tests/OddNumberTest.php new file mode 100644 index 0000000..211d8eb --- /dev/null +++ b/tests/OddNumberTest.php @@ -0,0 +1,27 @@ + [new OddNumber]]; + + // Execute the tests + $this->assertFalse(validator(['number' => '0'], $rule)->passes()); + $this->assertTrue(validator(['number' => '1'], $rule)->passes()); + $this->assertFalse(validator(['number' => '2'], $rule)->passes()); + $this->assertTrue(validator(['number' => '3'], $rule)->passes()); + } + +} \ No newline at end of file diff --git a/tests/TitlecaseTest.php b/tests/TitlecaseTest.php new file mode 100644 index 0000000..96e9cf8 --- /dev/null +++ b/tests/TitlecaseTest.php @@ -0,0 +1,28 @@ + [new Titlecase]]; + + // Execute the tests + $this->assertFalse(validator(['text' => 'hello world'], $rule)->passes()); + $this->assertFalse(validator(['text' => 'Hello world'], $rule)->passes()); + $this->assertFalse(validator(['text' => 'hello World'], $rule)->passes()); + $this->assertTrue(validator(['text' => 'Hello World'], $rule)->passes()); + $this->assertTrue(validator(['text' => 'HELLO WORLD'], $rule)->passes()); + } + +} \ No newline at end of file diff --git a/tests/UppercaseTest.php b/tests/UppercaseTest.php new file mode 100644 index 0000000..3f242d5 --- /dev/null +++ b/tests/UppercaseTest.php @@ -0,0 +1,25 @@ + [new Uppercase]]; + + // Execute the tests + $this->assertFalse(validator(['text' => 'hello'], $rule)->passes()); + $this->assertTrue(validator(['text' => 'HELLO'], $rule)->passes()); + } + +} \ No newline at end of file