diff --git a/baked_in.go b/baked_in.go index 57440cb..91fd479 100644 --- a/baked_in.go +++ b/baked_in.go @@ -2015,6 +2015,9 @@ func isLowercase(fl FieldLevel) bool { field := fl.Field() if field.Kind() == reflect.String { + if field.String() == "" { + return false + } return field.String() == strings.ToLower(field.String()) } @@ -2026,6 +2029,9 @@ func isUppercase(fl FieldLevel) bool { field := fl.Field() if field.Kind() == reflect.String { + if field.String() == "" { + return false + } return field.String() == strings.ToUpper(field.String()) } diff --git a/validator_test.go b/validator_test.go index 1114071..f5d6d01 100644 --- a/validator_test.go +++ b/validator_test.go @@ -9011,7 +9011,7 @@ func TestLowercaseValidation(t *testing.T) { }{ {`abcdefg`, true}, {`Abcdefg`, false}, - {"", true}, + {"", false}, } validate := New() @@ -9048,7 +9048,7 @@ func TestUppercaseValidation(t *testing.T) { }{ {`ABCDEFG`, true}, {`aBCDEFG`, false}, - {"", true}, + {"", false}, } validate := New()