Created
June 16, 2014 06:26
-
-
Save bmount/f61b81378a60274ca50b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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