# Centralizing validation for multiple AR models

**URL:** <https://www.ruby-forum.com/t/centralizing-validation-for-multiple-ar-models/69251>\
**Category:** Rails\
**Created:** [September 19, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/centralizing-validation-for-multiple-ar-models/69251 "2006-09-19T18:33:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [September 19, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/centralizing-validation-for-multiple-ar-models/69251/1 "2006-09-19T18:33:01Z")

</div>

I have several ActiveRecord models that contain email addresses and I’d  
like to be able to DRY up the validation for them so I only have to put  
the appropriate regex in one place. Currently each model has its own  
“validates\_format\_of” with the same regex provided for the appropriate  
email field.

Some options:

1. One option is to use composed\_of - would this work for me? I’d need  
to compose each email field as an EmailAddress model object in my  
various models.

2. Alternatively, there seems to be an opportunity here for declaring  
validations that span models - either by naming them, or pointing to a  
method somewhere, etc.  
Then I could just say “validates\_format\_of by using this code that I’m  
referencing” in my model objects.

Thoughts?

Wes
