# ?Conditional validation skipping?

**URL:** <https://www.ruby-forum.com/t/conditional-validation-skipping/121790>\
**Category:** Ruby\
**Created:** [November 30, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/conditional-validation-skipping/121790 "2007-11-30T22:15:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [November 30, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/conditional-validation-skipping/121790/1 "2007-11-30T22:15:58Z")

</div>

Hey,

I have validation that I need to be able to bypass depending on a cookie  
that the user might have.

My problem is for most users, they have to have a .edu or .com email  
address. So I wrote that into the validation.

But if a certain cookie is set, I want to allow them to register with  
any email address, and still run the other validations (uniqueness of  
email, etc.)

Does anyone have any information on how to do this?

USER MODEL  
validates\_presence\_of :first\_name, :last\_name, :email, :password  
validates\_uniqueness\_of :email  
validates\_format\_of :email,  
:with =\> %r{.(edu|com)$}i,  
:message =\> “Must be a valid email address”

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [November 30, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/conditional-validation-skipping/121790/2 "2007-11-30T22:42:00Z")

</div>

On Nov 30, 2007 4:15 PM, Joe P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> email, etc.)
> 
> Does anyone have any information on how to do this?
> 
> USER MODEL  
> validates\_presence\_of :first\_name, :last\_name, :email, :password  
> validates\_uniqueness\_of :email  
> validates\_format\_of :email,  
> :with =\> %r{.(edu|com)$}i,  
> :message =\> “Must be a valid email address”

Maybe use a filter in the controller that does registration. Try the  
rails list for more help:  
[http://groups.google.com/group/rubyonrails-talk](http://groups.google.com/group/rubyonrails-talk)  
or  
[http://www.ruby-forum.com/forum/3](http://www.ruby-forum.com/forum/3)  
on ruby-forum.

-A
