The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
validates_format_of a ZIP or Postal Code in Ruby on Rails

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Nathaniel Brown

Posts: 54
Nickname: nshb
Registered: Oct, 2005

Nathaniel Brown is Technology Consultant in Vancouver, Canada
validates_format_of a ZIP or Postal Code in Ruby on Rails Posted: Oct 11, 2007 12:48 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Nathaniel Brown.
Original Post: validates_format_of a ZIP or Postal Code in Ruby on Rails
Feed Title: Nathaniel Brown
Feed URL: http://feeds.feedburner.com/nshb
Feed Description: Insight as a professional Technology Consltant and Photographer.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Nathaniel Brown
Latest Posts From Nathaniel Brown

Advertisement

When it comes to building an address model, validation is obviously important to ensure that the data you actually do collect is relatively trustworthy.

I have written up a Regular Expression for those who are interested which accepts both US based ZIP Codes and the Canadian Postal Code.

Here it is...

validates_format_of :zip_postal_code, :with => /((^([a-z]\d[a-z])\s?(\d[a-z]\d)$)|(^([0-9]{5})(-?\d{4})?$))/is

Read: validates_format_of a ZIP or Postal Code in Ruby on Rails

Topic: Time.today going away Previous Topic   Next Topic Topic: Y-combinator in Ruby with REAL λ!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use