# 3 questions

**URL:** <https://www.ruby-forum.com/t/3-questions/91956>\
**Category:** Rails\
**Created:** [April 13, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/3-questions/91956 "2007-04-13T19:16:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raven13](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b3f665/32.png) [@raven13](https://www.ruby-forum.com/u/raven13)\
**Post date:** [April 13, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/3-questions/91956/1 "2007-04-13T19:16:57Z")

</div>

1. 

validates\_format\_of :name, :with =\> /\A(\w(?:[/’ -.])?)\*\Z/i

What does the ‘i’ do at the end of the regular expression?

1. 

Should I do validation for attributes that are not from a form?

1. 

def self.up  
create\_table :customers do |t|  
t.column :number, :integer, :limit =\> 4  
end  
end

As far as I know, Mysql 5.0.27 uses Int for number here. Will also a  
small number need 4 bytes in the database?

---

<div class="post-metadata">

**Author:** ![raven13](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b3f665/32.png) [@raven13](https://www.ruby-forum.com/u/raven13)\
**Post date:** [April 13, 2007, 7:42pm UTC](https://www.ruby-forum.com/t/3-questions/91956/2 "2007-04-13T19:42:59Z")

</div>

> validates\_format\_of :name, :with =\> /\A(\w(?:[/’ -.])?)\*\Z/i
> 
> What does the ‘i’ do at the end of the regular expression?

/i makes a regex case-insensitive. See  
[http://www.ruby-doc.org/core/classes/Regexp.html#M001219](http://www.ruby-doc.org/core/classes/Regexp.html#M001219)  
for other Regexp options

---

<div class="post-metadata">

**Author:** ![raven13](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b3f665/32.png) [@raven13](https://www.ruby-forum.com/u/raven13)\
**Post date:** [April 13, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/3-questions/91956/3 "2007-04-13T20:04:23Z")

</div>

Hi Martin,

Martin Luy wrote:

> 1. 
> 
> validates\_format\_of :name, :with =\> /\A(\w(?:[/’ -.])?)\*\Z/i
> 
> What does the ‘i’ do at the end of the regular expression?

It makes the match case insensitive

> 1. 
> 
> Should I do validation for attributes that are not from a form?

Yes. If you expect a field to conform to condition that is not inherent  
in it’s column type you should validate the data. It will catch bugs  
and keep you data more coherent.

> 1. 
> 
> def self.up  
> create\_table :customers do |t|  
> t.column :number, :integer, :limit =\> 4  
> end  
> end
> 
> As far as I know, Mysql 5.0.27 uses Int for number here. Will also a  
> small number need 4 bytes in the database?

Yes. It really isn’t a big deal. There are ways around this, but  
before you go hacking into the code ask yourself if this isn’t premature  
optimization. unless you are storing ~10^6 rows your space savings will  
not be appreciable.

J. F. Miller

---

<div class="post-metadata">

**Author:** ![raven13](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b3f665/32.png) [@raven13](https://www.ruby-forum.com/u/raven13)\
**Post date:** [April 13, 2007, 8:06pm UTC](https://www.ruby-forum.com/t/3-questions/91956/4 "2007-04-13T20:06:07Z")

</div>

Martin Luy wrote:

> 1. 
> 
> validates\_format\_of :name, :with =\> /\A(\w(?:[/’ -.])?)\*\Z/i
> 
> What does the ‘i’ do at the end of the regular expression?

Case-insensitive

> 1. 
> 
> Should I do validation for attributes that are not from a form?

Depends on how much you trust yourself. Where is the data coming from?

> 1. 
> 
> def self.up  
> create\_table :customers do |t|  
> t.column :number, :integer, :limit =\> 4  
> end  
> end
> 
> As far as I know, Mysql 5.0.27 uses Int for number here. Will also a  
> small number need 4 bytes in the database?

As far as I can tell, it doesn’t matter what “limit” you give to an int  
in MySQL , it always uses 4 bytes. I don’t believe you have access to  
the various int types (bigint, smallint, mediumint) through migrations.

-matthew
