Created
February 6, 2014 20:05
-
-
Save laser/8851580 to your computer and use it in GitHub Desktop.
zip in state validation
This file contains hidden or 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
# in some shared file | |
SomeNamespace.isZipInState = (zip, state) -> | |
ranges = STATE_RANGES[state] | |
return true if ! ranges? || ! zip | |
zip = value.match(/^\D*(\d\D*){5}/)[0] | |
zip = parseInt zip.replace(/\D/g,'') if zip | |
return true if ! zip | |
results = [] | |
for range in ranges | |
do (range) -> | |
results.push zip >= range[0] && zip <= range[1] | |
return (true in results) | |
# ZestCash view | |
zip_in_state_validator = (value, elem) => | |
state = $('.zestcash.whatever fieldset derp [name=state]').val() | |
SomeNamespace.isZipInState value, state | |
# Spotloan view | |
zip_in_state_validator = (value, elem) => | |
state = $('.spotloan something [name=state]').val() | |
SomeNamespace.isZipInState value, state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment