Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save awesome/6124464 to your computer and use it in GitHub Desktop.
Save awesome/6124464 to your computer and use it in GitHub Desktop.
# http://rubular.com/r/4DIAmT5J7U
# http://en.wikipedia.org/wiki/ZIP_code#ZIP.2B4
# multi-line string
# /^(\d{4,5}$)|(\d{5}-?\d{4}$)/
# single-line string
# /\A(\d{4,5}\z)|(\d{5}-?\d{4}\z)/
#ZIP CODE REGEXP by SoAwesomeMan
#9999
#99999
#99999-9999
#999999999
validates_format_of :zipcode, :with => /\A(\d{4,5}\z)|(\d{5}-?\d{4}\z)/
validates_length_of :zipcode, :minimum => 4, :maximum => 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment