Allow latitude/longitude validation for numeric values

pull/440/head
Ramy Aboul Naga 6 years ago
parent cdd5c28d21
commit 52ea448998
  1. 4
      baked_in.go
  2. 8
      validator_test.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. // IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate.
func isLongitude(fl FieldLevel) bool { 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. // IsLatitude is the validation function for validating if the field's value is a valid latitude coordinate.
func isLatitude(fl FieldLevel) bool { 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. // IsDataURI is the validation function for validating if the field's value is a valid data URI.

@ -3335,7 +3335,7 @@ func TestSSNValidation(t *testing.T) {
func TestLongitudeValidation(t *testing.T) { func TestLongitudeValidation(t *testing.T) {
tests := []struct { tests := []struct {
param string param interface{}
expected bool expected bool
}{ }{
{"", false}, {"", false},
@ -3344,6 +3344,8 @@ func TestLongitudeValidation(t *testing.T) {
{"+73.234", true}, {"+73.234", true},
{"+382.3811", false}, {"+382.3811", false},
{"23.11111111", true}, {"23.11111111", true},
{-180, true},
{180.1, false},
} }
validate := New() validate := New()
@ -3371,7 +3373,7 @@ func TestLongitudeValidation(t *testing.T) {
func TestLatitudeValidation(t *testing.T) { func TestLatitudeValidation(t *testing.T) {
tests := []struct { tests := []struct {
param string param interface{}
expected bool expected bool
}{ }{
{"", false}, {"", false},
@ -3380,6 +3382,8 @@ func TestLatitudeValidation(t *testing.T) {
{"47.1231231", true}, {"47.1231231", true},
{"+99.9", false}, {"+99.9", false},
{"108", false}, {"108", false},
{-90, true},
{90, true},
} }
validate := New() validate := New()

Loading…
Cancel
Save