# Validates\_length\_of for NUMBER data type

**URL:** <https://www.ruby-forum.com/t/validates-length-of-for-number-data-type/120820>\
**Category:** Rails\
**Created:** [November 20, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/validates-length-of-for-number-data-type/120820 "2007-11-20T21:16:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [November 20, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/validates-length-of-for-number-data-type/120820/1 "2007-11-20T21:16:12Z")

</div>

Hi,

When column’s data type is NUMBER (oracle) validates\_length\_of doesn’t  
seem to work.

validates\_length\_of :bsa, :maximum=\>3

I get error message even though I didn’t put anything and if I enter  
something, I get ‘size’ is undefined error.

If I do that:  
validates\_length\_of :bsa, :within =\> 1…999 , :allow\_nil =\> true

I get wrong number of arguments (1 for 0) error.

I also googled, but could find specific way of validates length of  
number data type.

thanks in advance,

---

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [November 20, 2007, 9:29pm UTC](https://www.ruby-forum.com/t/validates-length-of-for-number-data-type/120820/2 "2007-11-20T21:29:47Z")

</div>

On Nov 20, 2007 2:15 PM, kimda [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> When column’s data type is NUMBER (oracle) validates\_length\_of doesn’t  
> seem to work.
> 
> validates\_length\_of :bsa, :maximum=\>3

validates\_length\_of is for validating string lengths.

> I also googled, but could find specific way of validates length of  
> number data type.

Override the validate method in the model.

def validate  
if bsa \> 999 errors.add( :bsa, ‘too big’ )  
if bsa \< 1 errors.add( :bsa, ‘too small’ )  
end

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [November 20, 2007, 10:06pm UTC](https://www.ruby-forum.com/t/validates-length-of-for-number-data-type/120820/3 "2007-11-20T22:06:10Z")

</div>

Great! It works. Thank you so much!
