How can I explain this. I have a list of postcodes in text files in an external url and I have a formfield.

When people enter data into the form field, using javascript validation, I want the form to check if the entered data exists in any of the external postcode files.

Is there anyway this can be possible ? if so can you please explain.

Thanks in advance.

Dani AI

Generated

has a large, split dataset (≈2 million UK postcodes on external flat files), so pulling the full list into the browser is impractical. A reliable, fast solution is a small server-side lookup service that returns JSON prefix matches. That addresses bandwidth, memory, and speed problems. ’s point about needing more than plain client JS is correct, and ’s autocomplete UI idea suits the front end — but the UI still needs a backend that can answer prefix queries quickly.

Practical server-side workflow: merge and normalize the flat files into a canonical list (uppercase, remove extra spaces); load that into an indexed store (a DB table with a B-tree index on postcode works well – queries like WHERE postcode LIKE 'PREFIX%' LIMIT 10 are efficient when indexed). If a DB is impossible, pre-shard the files by prefix (first 2–3 chars) so lookups only open a small file. For higher scale or fuzzy needs, Redis or a search engine (Elasticsearch) are alternatives, but start simple and measure.

Client-side behavior: debounce typing (≈300 ms), normalize input (uppercase, strip spaces) before querying, show a short list (e.g. 10) of suggestions, and perform an exact-match server lookup on submit to validate. A minimal debounce + fetch pattern:

function debounce(fn, wait) {
  let t;
  return (...args) => { clearTimeout(t); t = setTimeout(() => fn(...args), wait); };
}

const suggest = debounce(query => {
  if (!query) return;
  fetch('/api/postcodes?q=' + encodeURIComponent(query))
    .then(r => r.json())
    .then(list => { /* render suggestions */ })
    .catch(() => { /* graceful fallback */ });
}, 300);

Troubleshooting & cautions: do not expose the full dataset to clients; cache popular prefixes and use server-side rate limits; normalize and validate server-side (regexes help but authoritative validation is an exact dataset lookup); log slow queries and add a computed prefix column or shard if LIKE queries are slow. These steps implement the earlier suggestions into a concrete, production-friendly approach.

Recommended Answers

All 4 Replies

This may be possible. What have you tried? Please demonstrate some effort!

I have over 2 million UK postcodes in multiple flat files and I have a static search field.

When people enter data into the search field, I want the field to guess or autocomplete the field based on the data input.

So when a visitor is entering their postcode in the field, I don't know how to make it happen that the fields prediction or autocomplete is fetched from the multiple postcode flat files.

I have thought of using a simple dropdown list, but that would be a very long list as you can imagin.

I really need help with this.

you wouldn't be able to do this with plain js you'd need to use ajax and return a json list of possible values from your external file(s)

thousands in flat files sounds like a terrible idea, you might want to consider a database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.