diff --git a/README.md b/README.md index a00ca95..7773a20 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,24 @@ The given value must be formatted in [Kebab case](https://en.wikipedia.org/wiki/ public Intervention\Validation\Rules\Kebabcase::__construct() +### Latitude + +Checks for a valid geographic [Latitude](https://en.wikipedia.org/wiki/Latitude). + + public Intervention\Validation\Rules\Latitude::__construct() + +### Longitude + +Checks for a valid geographic [Longitude](https://en.wikipedia.org/wiki/Longitude). + + public Intervention\Validation\Rules\Longitude::__construct() + +### LatLng + +Checks for a valid geographic comma separated pair of a [Latitude](https://en.wikipedia.org/wiki/Latitude) and a [Longitude](https://en.wikipedia.org/wiki/Longitude). + + public Intervention\Validation\Rules\LatLng::__construct() + ### Lower case string The given value must be all lower case letters. diff --git a/src/Rules/LatLng.php b/src/Rules/LatLng.php new file mode 100644 index 0000000..1503d37 --- /dev/null +++ b/src/Rules/LatLng.php @@ -0,0 +1,18 @@ +pattern(), 2, -2); + $lng = substr((new Longitude())->pattern(), 2, -2); + + return "/^" . $lat . ", ?" . $lng . "$/"; + } +} diff --git a/src/Rules/Latitude.php b/src/Rules/Latitude.php new file mode 100644 index 0000000..2d7e626 --- /dev/null +++ b/src/Rules/Latitude.php @@ -0,0 +1,15 @@ + 'Der Wert :attribute einhält keinen gültigen Internet Media Type (MIME-Type).', 'austrianinsurancenumber' => 'Der Wert :attribute enthält keine gültige österreichische Versicherungsnummer', 'grid' => 'Der Wert :attribute enthält keinen gültige Global Release Identifier (GRid).', + 'latitude' => 'Der Wert :attribute enthält keine gültige geographische Breite.', + 'longitude' => 'Der Wert :attribute enthält keine gültige geographische Länge.', + 'latlng' => 'Der Wert :attribute enthält keine gültige geographischen Koordinaten.', ]; diff --git a/src/lang/en/validation.php b/src/lang/en/validation.php index 30fc9fd..5fb4c29 100644 --- a/src/lang/en/validation.php +++ b/src/lang/en/validation.php @@ -35,4 +35,7 @@ 'mimetype' => 'The value :attribute does not contain a valid Internet Media Type (MIME-Type).', 'austrianinsurancenumber' => 'The value :attribute does not contain a valid austrian insurance number.', 'grid' => 'The value :attribute must be a valid Global Release Identifier (GRid).', + 'latitude' => 'The value :attribute must be a valid geographical latitude.', + 'longitude' => 'The value :attribute must be a valid geographical longitude.', + 'latlng' => 'The value :attribute must be valid geographical coordinates.', ]; diff --git a/tests/Rules/LatLngTest.php b/tests/Rules/LatLngTest.php new file mode 100644 index 0000000..c2c852a --- /dev/null +++ b/tests/Rules/LatLngTest.php @@ -0,0 +1,59 @@ +isValid($value); + $this->assertEquals($result, $valid); + } + + public static function dataProvider(): array + { + return [ + [true, '0, 0'], + [true, '-80, 90'], + [true, '0, +90'], + [true, '+50, -180'], + [true, '90, 180'], + [true, '-19.123, +180'], + [true, '0.11111, 12.123'], + [true, '+89.00000, +12.123'], + [true, '0.00000, -12.123'], + [true, '+89.00000, -90'], + [true, '89.99999, +90'], + [true, '90, 150'], + [true, '-90, 34.112311'], + [true, '0,0'], + [true, '-80,90'], + [true, '0,+90'], + [true, '+50,-180'], + [true, '90,180'], + [true, '-19.123,+180'], + [true, '0.11111,12.123'], + [true, '+89.00000,+12.123'], + [true, '0.00000,-12.123'], + [true, '+89.00000,-90'], + [true, '89.99999,+90'], + [true, '90,150'], + [true, '-90,34.112311'], + [false, '91, 0'], + [false, '-91, 9'], + [false, '90.000001, 0'], + [false, '-90.000001, 0'], + [false, '0, -200'], + [false, '0, -180.12'], + [false, '0, 180.12'], + [false, '0, +180.12'], + ]; + } +} diff --git a/tests/Rules/LatitudeTest.php b/tests/Rules/LatitudeTest.php new file mode 100644 index 0000000..b05ac8d --- /dev/null +++ b/tests/Rules/LatitudeTest.php @@ -0,0 +1,41 @@ +isValid($value); + $this->assertEquals($result, $valid); + } + + public static function dataProvider(): array + { + return [ + [true, '-80'], + [true, '0'], + [true, '+50'], + [true, '90'], + [true, '-19.123'], + [true, '0.11111'], + [true, '+89.00000'], + [true, '0.00000'], + [true, '+89.00000'], + [true, '89.99999'], + [true, '90'], + [true, '-90'], + [false, '91'], + [false, '-91'], + [false, '90.000001'], + [false, '-90.000001'], + ]; + } +} diff --git a/tests/Rules/LongitudeTest.php b/tests/Rules/LongitudeTest.php new file mode 100644 index 0000000..d9fff49 --- /dev/null +++ b/tests/Rules/LongitudeTest.php @@ -0,0 +1,37 @@ +isValid($value); + $this->assertEquals($result, $valid); + } + + public static function dataProvider(): array + { + return [ + [true, '0'], + [true, '+90'], + [true, '-90'], + [true, '90'], + [true, '+90.0000001'], + [true, '-90.0000001'], + [true, '90.00000001'], + [true, '+180'], + [true, '-180'], + [true, '180'], + [false, '180.0001'], + [false, '-180.0001'], + ]; + } +}