diff --git a/README.md b/README.md index cc494bd..a75fed0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Package validator ================ [![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -![Project status](https://img.shields.io/badge/version-9.16.1-green.svg) +![Project status](https://img.shields.io/badge/version-9.17.0-green.svg) [![Build Status](https://semaphoreci.com/api/v1/joeybloggs/validator/branches/v9/badge.svg)](https://semaphoreci.com/joeybloggs/validator) [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=v9&service=github)](https://coveralls.io/github/go-playground/validator?branch=v9) [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator) diff --git a/baked_in.go b/baked_in.go index 64b71cb..3f87da4 100644 --- a/baked_in.go +++ b/baked_in.go @@ -1097,12 +1097,22 @@ func isHexadecimal(fl FieldLevel) bool { // IsNumber is the validation function for validating if the current field's value is a valid number. func isNumber(fl FieldLevel) bool { - return numberRegex.MatchString(fl.Field().String()) + switch fl.Field().Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64: + return true + default: + return numberRegex.MatchString(fl.Field().String()) + } } // IsNumeric is the validation function for validating if the current field's value is a valid numeric value. func isNumeric(fl FieldLevel) bool { - return numericRegex.MatchString(fl.Field().String()) + switch fl.Field().Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64: + return true + default: + return numericRegex.MatchString(fl.Field().String()) + } } // IsAlphanum is the validation function for validating if the current field's value is a valid alphanumeric value. diff --git a/doc.go b/doc.go index 6eef72c..be93d79 100644 --- a/doc.go +++ b/doc.go @@ -538,6 +538,7 @@ Numeric This validates that a string value contains a basic numeric value. basic excludes exponents etc... +for integers or float it returns true. Usage: numeric diff --git a/validator_test.go b/validator_test.go index 463bd83..0823812 100644 --- a/validator_test.go +++ b/validator_test.go @@ -6241,8 +6241,7 @@ func TestNumber(t *testing.T) { i := 1 errs = validate.Var(i, "number") - NotEqual(t, errs, nil) - AssertError(t, errs, "", "", "", "", "number") + Equal(t, errs, nil) } func TestNumeric(t *testing.T) { @@ -6285,8 +6284,7 @@ func TestNumeric(t *testing.T) { i := 1 errs = validate.Var(i, "numeric") - NotEqual(t, errs, nil) - AssertError(t, errs, "", "", "", "", "numeric") + Equal(t, errs, nil) } func TestAlphaNumeric(t *testing.T) {