# Fields when entered needs to be validated

**URL:** <https://www.ruby-forum.com/t/fields-when-entered-needs-to-be-validated/174064>\
**Category:** Rails\
**Created:** [August 20, 2009, 9:24am UTC](https://www.ruby-forum.com/t/fields-when-entered-needs-to-be-validated/174064 "2009-08-20T09:24:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 20, 2009, 9:24am UTC](https://www.ruby-forum.com/t/fields-when-entered-needs-to-be-validated/174064/1 "2009-08-20T09:24:25Z")

</div>

hi guys

Thanks for the support you give

I have some four fields which is not mandatory, but when that field is  
entered need to be validated before saved

else

it can take null value

can you please guide me

–  
Karthik.k  
Mobile - +91-9894991640

---

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 20, 2009, 9:34am UTC](https://www.ruby-forum.com/t/fields-when-entered-needs-to-be-validated/174064/2 "2009-08-20T09:34:22Z")

</div>

2009/8/20 karthik k [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> can you please guide me

Have a look at the rails guide on validations,  
[http://guides.rubyonrails.org/activerecord\_validations\_callbacks.html](http://guides.rubyonrails.org/activerecord_validations_callbacks.html)

Colin

---

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 21, 2009, 7:08am UTC](https://www.ruby-forum.com/t/fields-when-entered-needs-to-be-validated/174064/3 "2009-08-21T07:08:37Z")

</div>

On Thu, Aug 20, 2009 at 4:34 PM, Rails L. \<  
removed\_email\_address@domain.invalid\> wrote:

> > can you please guide me  
> > validates\_numericality\_of :age, :allow\_blank=\>true  
> > end
> 
> This will let blank but when something is there it will be validated for  
> numbers.
> 
> [http://www.classifiedscript.in](http://www.classifiedscript.in)  
> Craigslist Clone

Hi

Thank you

–  
Karthik.k  
Mobile - +91-9894991640

---

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 20, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/fields-when-entered-needs-to-be-validated/174064/4 "2009-08-20T13:04:27Z")

</div>

Karthik Kantharaj wrote:

> hi guys
> 
> Thanks for the support you give
> 
> ## I have some four fields which is not mandatory, but when that field is entered need to be validated before saved else it can take null value can you please guide me
> 
> Karthik.k  
> Mobile - +91-9894991640

Assume that you have an age field that should not be validated if it is  
blank. But should be validated when something is entered

#your Model

class Employee \< ActiveRecord::Base  
validates\_numericality\_of :age, :allow\_blank=\>true  
end

This will let blank but when something is there it will be validated for  
numbers.

[http://www.classifiedscript.in](http://www.classifiedscript.in)  
Craigslist Clone
