Skip to content

Instantly share code, notes, and snippets.

@bmount
Created June 16, 2014 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmount/f61b81378a60274ca50b to your computer and use it in GitHub Desktop.
Save bmount/f61b81378a60274ca50b to your computer and use it in GitHub Desktop.
<!doctype html>
<meta charset="utf-8">
<body>
<form action=# method="GET">
Zip code: <input id=zip-query type="text" name="zip" />
<input id=zip-submit type="submit" value="Submit" />
</form>
<script>
function checkZipRange(userZip) {
// ignore 9-digit zip additional routing info
userZip = Number(userZip.substring(0,5));
console.log(userZip);
if (isNaN(userZip)) return false;
// This relies on the observation that SF zip codes seem to
// be in this range. Use something more complete IRL:
if (userZip > 94101 && userZip < 94134) {
return true;
}
return false;
}
var submit = document.querySelector("#zip-submit"),
zipQuery = document.querySelector("#zip-query");
submit.addEventListener("click", function (evt) {
evt.preventDefault();
evt.stopPropagation();
answer = checkZipRange(zipQuery.value);
if (answer) alert("Yea");
else alert("Nay");
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment