Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 188419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:01:19+00:00 2026-05-11T16:01:19+00:00

I made this small location class so that I can better handle address information

  • 0

I made this small location class so that I can better handle address information which I am going to be sending off in requests to the Google Maps API. One thing I have left to do is some validation to make sure that the address has enough information to return a result back.

For the application, the level of accuracy should be as loose as a single City (meaning that it should work as long as a zip code or city/state is provided since it will find the geographic center of that area automatically in Google Maps).

So things like:

  • Address1, Address2, City, State, ZIP
  • Address1, City, State, ZIP
  • Address1, City, ZIP
  • Address1, ZIP
  • City, State

Should all work, while something like

  • Address1, Address2, State
  • State
  • City
  • Address1
  • Address2
  • Address1, Address2

Would not work because it would either return potentially numerous results or would put the geographic center outside my desired scope of precision.

NOTE I am sure I could list dozens of other combinations that work and do not work, but I hope I gave enough examples to properly outline the “scope of precision” here.

Public Class Location
    Private _Address1 As String
    Private _Address2 As String
    Private _City As String
    Private _State As String
    Private _ZIP As String

    Public Function isValid() As Boolean   
        'Insert validation code here'
    End Function

End Class

I know that you can make this using a whole gaggle of If statements checking if something exists and if something else exists, and if something else does not exist, on and on, but I feel as if that would be a huge chunk of logic code.

Is there a more efficient/elegant way of making sure I have a valid Location before I send it out in the request?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:01:20+00:00Added an answer on May 11, 2026 at 4:01 pm

    In terms of required items, your rules really boil down to:

    A valid address must have either a ZIP code or both a city and state.

    As far as I can see, everything that satisfies that rule should be OK. Your validation code can be as simple as:

    Public Function isValid() As Boolean   
        If (String.IsNullOrEmpty(city) or String.IsNullOrEmpty(state)) And _
            String.IsNullOrEmpty(zip) Then
    
            Return False
        Else
            Return True
        End If
    End Function
    

    Obviously, you’ll probably also want to check that the values within the field conform to expectations (proper ZIP length, valid state, etc.)

    As an aside, you might want to consider returning something more than a boolean from the IsValid check. If the result is valid, a simple true will suffice, but often with false return values you want to know why it is not valid. I usually do something like:

    Class ValidationResult
        Public Property IsValid as Boolean
        Public Property Errors as IEnumerable<String>
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made this decorator, which results in an infinite redirect loop. The problem is
This is something that made me doubt for a while so I thought it
Since I'm sure many people have different standard, I've made this post a community
I wonder if someone knows if there is a pre-made solution for this: I
I have roughly the following code. Could this be made nicer or more efficient?
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
As made clear in update 3 on this answer , this notation: var hash
This is the day of weird behavior. We have a Win32 project made with
This is a second-hand question from an OS development site, but it made me
Coming from this question , I have a wxComboCtrl with a custom popup made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.