Validating address fields

Posts: 20
Joined: 10/01/2007

I am looking for a way to validate address fields few examples:

  • Make sure the street is not 'POB'
  • Make sure postal code is 5 numeric in the US, 6 alphanumeric in canada, etc.
  • Phone number validation
  • Email address

I didn't see any _validate functions or hooks to use, and I don't want to hack ubercart core for this, since I guess the validation might be different for each case - I just want to know what you think is the best way to add such code.

Posts: 2352
Joined: 08/07/2007
AdministratoreLiTe!

You can try writing a custom module that uses form_alter() to add validate handlers to those fields. I used to have validation on ZIP code and phone numbers, up until people outside of the US started using it.

Posts: 329
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

I think it's quite good to have postal/zip code validation. There is a contribution for osCommerce that I used which uses JavaScript to validate a UK postcode. If a system where implemented it should be able to handle most common postal code formats and be easy to extend to add validation for users.

Posts: 329
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

As well as checking for the correct format and adding a space in the correct place the letters are converted to uppercase.