# Blank fields getting validated

**URL:** <https://www.ruby-forum.com/t/blank-fields-getting-validated/88301>\
**Category:** Rails\
**Created:** [March 9, 2007, 2:45pm UTC](https://www.ruby-forum.com/t/blank-fields-getting-validated/88301 "2007-03-09T14:45:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Love\_AJAX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@Love\_AJAX](https://www.ruby-forum.com/u/Love_AJAX)\
**Post date:** [March 9, 2007, 2:45pm UTC](https://www.ruby-forum.com/t/blank-fields-getting-validated/88301/1 "2007-03-09T14:45:05Z")

</div>

Hi,

I am not sure if this is already answered in this list. I couldn’t  
find an answer. So I am posting the question.

I have multiple validations for a field. For example:

validates\_presence\_of :contact\_email

validates\_format\_of :contact\_email,  
:with =\>  
/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i,  
:message =\> “is not a valid email address”

When I submit the form with a blank contact\_email I get 2 error  
messages:  
Contact email is not a valid email address  
Contact email can’t be blank

If the field is blank the second validations obviously fails.

I think Rails should look for blankness of the field and then just  
show one error message saying it’s a blank field.

Any solutions or workarouns?

Thanks much.

---

<div class="post-metadata">

**Author:** ![Love\_AJAX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@Love\_AJAX](https://www.ruby-forum.com/u/Love_AJAX)\
**Post date:** [March 9, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/blank-fields-getting-validated/88301/2 "2007-03-09T15:07:15Z")

</div>

Love AJAX wrote:

> When I submit the form with a blank contact\_email I get 2 error messages:  
> Contact email is not a valid email address  
> Contact email can’t be blank

:allow\_nil =\> true

See the Default\_Validation\_Options under  
ActiveRecord::Validations::ClassMethods at [http://api.rubyonrails.org/](http://api.rubyonrails.org/)

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![Love\_AJAX](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@Love\_AJAX](https://www.ruby-forum.com/u/Love_AJAX)\
**Post date:** [March 10, 2007, 8:07am UTC](https://www.ruby-forum.com/t/blank-fields-getting-validated/88301/3 "2007-03-10T08:07:11Z")

</div>

Even this doesn’t work. I checked the values of attributes and blank  
fields are not nil. It appears to be blank. So the validations are  
taking place.
