relationships/src/Rules/Coordinate.php
<?php
namespace Alimentalos\Relationships\Rules;
use Illuminate\Contracts\Validation\Rule;
class Coordinate implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return is_null($value) || preg_match("/^[-]?((([0-8]?[0-9])(\.(\d{1,8}))?)|(90(\.0+)?)),\s?[-]?((((1[0-7][0-9])|([0-9]?[0-9]))(\.(\d{1,8}))?)|180(\.0+)?)$/", $value);
}
/**
* Get the validation error message.
*
* @return string
* @codeCoverageIgnore
*/
public function message()
{
return 'The :attribute must be a valid set of latitude and
longitude coordinates, with a limit of 8 digits after a
decimal point';
}
}