From 52ea44899849049e3ae9267ef1902c36807fe198 Mon Sep 17 00:00:00 2001 From: Ramy Aboul Naga Date: Thu, 24 Jan 2019 17:17:00 +0100 Subject: [PATCH] Allow latitude/longitude validation for numeric values --- baked_in.go | 4 ++-- validator_test.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/baked_in.go b/baked_in.go index 5fa0e22..0b7a545 100644 --- a/baked_in.go +++ b/baked_in.go @@ -304,12 +304,12 @@ func isSSN(fl FieldLevel) bool { // IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate. func isLongitude(fl FieldLevel) bool { - return longitudeRegex.MatchString(fl.Field().String()) + return longitudeRegex.MatchString(fmt.Sprint(fl.Field().Interface())) } // IsLatitude is the validation function for validating if the field's value is a valid latitude coordinate. func isLatitude(fl FieldLevel) bool { - return latitudeRegex.MatchString(fl.Field().String()) + return latitudeRegex.MatchString(fmt.Sprint(fl.Field().Interface())) } // IsDataURI is the validation function for validating if the field's value is a valid data URI. diff --git a/validator_test.go b/validator_test.go index 06cb617..98cacba 100644 --- a/validator_test.go +++ b/validator_test.go @@ -3335,7 +3335,7 @@ func TestSSNValidation(t *testing.T) { func TestLongitudeValidation(t *testing.T) { tests := []struct { - param string + param interface{} expected bool }{ {"", false}, @@ -3344,6 +3344,8 @@ func TestLongitudeValidation(t *testing.T) { {"+73.234", true}, {"+382.3811", false}, {"23.11111111", true}, + {-180, true}, + {180.1, false}, } validate := New() @@ -3371,7 +3373,7 @@ func TestLongitudeValidation(t *testing.T) { func TestLatitudeValidation(t *testing.T) { tests := []struct { - param string + param interface{} expected bool }{ {"", false}, @@ -3380,6 +3382,8 @@ func TestLatitudeValidation(t *testing.T) { {"47.1231231", true}, {"+99.9", false}, {"108", false}, + {-90, true}, + {90, true}, } validate := New()