Skip to content

Instantly share code, notes, and snippets.

@laser
Created February 6, 2014 20:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save laser/8851580 to your computer and use it in GitHub Desktop.
zip in state validation
# 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