# Validations on a field

**URL:** <https://www.ruby-forum.com/t/validations-on-a-field/175775>\
**Category:** Rails\
**Created:** [September 19, 2009, 11:01am UTC](https://www.ruby-forum.com/t/validations-on-a-field/175775 "2009-09-19T11:01:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [September 19, 2009, 11:01am UTC](https://www.ruby-forum.com/t/validations-on-a-field/175775/1 "2009-09-19T11:01:22Z")

</div>

hi, i have a model with 2 validations on a field

example:

validates\_presence\_of :email  
validates\_length\_of :email, :within =\> 6…100 #removed\_email\_address@domain.invalid  
validates\_uniqueness\_of :email  
validates\_format\_of :email, :with =\>  
Authentication.email\_regex

if i do the submit of form for a new object of the model with a blank  
mail  
i receive 4 errors.  
In this case i want receive only the errore for:  
validates\_presence\_of :email

is possible?

thanks

---

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [September 19, 2009, 12:18pm UTC](https://www.ruby-forum.com/t/validations-on-a-field/175775/2 "2009-09-19T12:18:18Z")

</div>

Luca R. wrote:

> hi, i have a model with 2 validations on a field
> 
> example:
> 
> validates\_presence\_of :email  
> validates\_length\_of :email, :within =\> 6…100 #removed\_email\_address@domain.invalid  
> validates\_uniqueness\_of :email  
> validates\_format\_of :email, :with =\>  
> Authentication.email\_regex
> 
> if i do the submit of form for a new object of the model with a blank  
> mail  
> i receive 4 errors.  
> In this case i want receive only the errore for:  
> validates\_presence\_of :email
> 
> is possible?
> 
> thanks

Add , :if =\> Proc.new { |user| !user.email.blank? } in other validation  
except validates\_presence\_of :email

like  
validates\_uniqueness\_of (:email,:if =\> Proc.new { |user|  
!user.email.blank? })
