validate_format_of

Hi, can you provide an actual example? For example,

P.O. Box 222

Santa Monica, CA 99999

1234 W 37th Street

Los Angeles, CA 93200

1234 W Jefferson Blvd

Apt. 6

Culver City, CA 90232

Now, does the above addresses represent the type of input you’re expecting? If so, then you should have similar column names:

address1

address2

location_no (Apt/Suite/…)

city

state

zipcode ( 5 + 4 )

If not, please provide an example of the address that you’re attempting to write a regular expression for. OK?

Good luck,

-Conrad

Hi Andrea, are you creating fields for each part of the address? If so, what are those fields and what should go into each? OK, I found an example,

Via Francesco Saverio Nitti, 28 00156 Roma

Thus, you should be able to use the following for the above:

()

I’m guessing that it would be easiest to input the address as follows using the above as an example:

= Via Francesco Saverio

= 28

= 00156

= Roma

Now, let’s add some validations within the model:

validates_presence_of :street, :postal_code, :city

validates_format_of :postal_code. :with => /[1]{5}$/

You should be able to add other validations as needed. Let me know if this is what you were looking to do.

-Conrad


  1. 0-9 ↩︎

Hi Andrea, I see what you’re talking about now. Is there a database that contains all the valid street names? If this is the case, then one could do a live search for the street field to set it or you can write a validate method that checks the street name against the database. If not, then you’ll have to implement a validate method to verify that the street name is correct based on the rules for Italy street names. Lastly, you might write the validate method verify that the entire address is correct. This would be equivalent to an address verification service for Italy. Guess what? Here’s a web service that verifies an address:

http://www.strikeiron.com/sample/GlobalAddress_v4_0/GlobalAddress.aspx

Also, it very very easy to use a web service from Rails. If you need information on this, please let me know and I will be glad to help.

-Conrad