Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow latitude/longitude validation for numeric values #440

Merged
merged 3 commits into from
Feb 12, 2019

Conversation

RaMin0
Copy link
Contributor

@RaMin0 RaMin0 commented Jan 24, 2019

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

Change Details:

  • Make latitude/longitude validation work with types other than strings.

@go-playground/admins

@coveralls
Copy link

coveralls commented Jan 24, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling d1d2da5 on RaMin0:feature/numeric_geo_coords into cdd5c28 on go-playground:v9.

@RaMin0 RaMin0 force-pushed the feature/numeric_geo_coords branch from c2f8e2c to 52ea448 Compare January 26, 2019 17:06
baked_in.go Outdated
@@ -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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like the change, it would be nice if you could add a type switch as it will allow the conversion from int to string to be much more efficient eg.

switch field.Kind() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a small benchmark to compare and you're right. Check the latest commits.

Copy link
Contributor

@deankarn deankarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool thanks, will try and merge in the next couple of days :)

@deankarn deankarn merged commit e10c2c9 into go-playground:v9 Feb 12, 2019
fairyhunter13 added a commit to fairyhunter13/validator that referenced this pull request Jul 12, 2020
…coords

Allow latitude/longitude validation for numeric values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants