www.webdeveloper.com
Results 1 to 3 of 3

Thread: Need Help Validating a Large set of numbers

  1. #1
    Join Date
    May 2011
    Posts
    3

    Question Need Help Validating a Large set of numbers

    Hi all,

    I was hoping to find some direction on this question.

    I have a project where when someone enters certain zip codes they will get redirected to another website. There are about 1206 zip codes that if someone enters they will get redirected. I was thinking about doing a very large conditional statement though that seemed very long and hard?

    Does any one have a better approach to this problem?

    Thanks!

  2. #2
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Yeah, a database!

    One way would to have AJAX calls to the server to fetch the URL to send the person to, then the use of a database will reduce the need for a large conditional in to a simple AJAX server side request.
    We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
    Code:
    Youre = {
          STILL_not_getting_it:function(){
               alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
          },
          MissingThePoint:function(msg){
                alert("You're missing the point. " + msg);
          }
    }
    Youre.STILL_not_getting_it();

  3. #3
    Join Date
    Feb 2006
    Posts
    2,930
    If you can group the codes as number ranges you can handle multiple instances with one redirect url.

    For example, this function returns a state code depending on the zip code, you can do something similar by defining the ranges to be redirected.


    Code:
    function stateFromZip(zip){
        zip= Number(zip);
        var A, statezips={
            AK:[99501, 99950], AL:[35004, 36925], AR:[71601, 72959], AR:[75502, 75502],
            AZ:[85001, 86556], CA:[90001, 96162], CO:[80001, 81658], CT:[6001, 6389],
            CT2:[6401, 6928], DC:[20001, 20039], DC2:[20042, 20599], DC3:[20799, 20799],
            DE:[19701, 19980], FL:[32004, 34997], GA:[30001, 31999], GA2:[39901, 39901],
            HI:[96701, 96898], IA:[50001, 52809], IA2:[68119, 68120], ID:[83201, 83876],
            IL:[60001, 62999], IN:[46001, 47997], KS:[66002, 67954], KY:[40003, 42788],
            LA:[70001, 71232], LA2:[71234, 71497], MA:[1001, 2791], MA2:[5501, 5544],
            MD:[20331, 20331], MD2:[20335, 20797], MD3:[20812, 21930], ME:[3901, 4992],
            MI:[48001, 49971], MN:[55001, 56763], MO:[63001, 65899], MS:[38601, 39776],
            MS2:[71233, 71233], MT:[59001, 59937], NC:[27006, 28909], ND:[58001, 58856],
            NE:[68001, 68118], NE2:[68122, 69367], NH:[3031, 3897], NJ:[7001, 8989],
            NM:[87001, 88441], NV:[88901, 89883], NY:[6390, 6390], NY2:[10001, 14975],
            OH:[43001, 45999], OK:[73001, 73199], OK2:[73401, 74966], OR:[97001, 97920],
            PA:[15001, 19640], RI:[2801, 2940], SC:[29001, 29948], SD:[57001, 57799],
            TN:[37010, 38589], TX:[73301, 73301], TX2:[75001, 75501], TX3:[75503, 79999],
            TX4:[88510, 88589], UT:[84001, 84784], VA:[20040, 20041], VA2:[20040, 20167],
            VA3:[20042, 20042], VA4:[22001, 24658], VT:[5001, 5495], VT2:[5601, 5907],
            WA:[98001, 99403], WI:[53001, 54990], WV:[24701, 26886], WY:[82001, 83128]
        }
        for(var z in statezips){
            A= statezips[z];
            if(statezips.hasOwnProperty(z) && zip> A[0] && zip< A[1]){
                return  z.substring(0, 2);
            }
        }
        return zip;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.41371 seconds
  • Memory Usage 2,860KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates