But 0 passes this regex -- it's one digit. If you wanted to ensure that you had n or more digits, you would use a regex like this:

^\d{2,}$

to match two or more digits.

Or, you could check to see if the first digit was larger than a 0 if that first digit cannot ever be 0:

^[1-9]\d*$

That will match 1, but not 0, and also 10, 11, 12 ...

Walter

On Aug 14, 2011, at 6:59 PM, Misha Ognev wrote:

Perhaps the input value is being cast to
an integer for storage, and so the trailing letters are being stripped
out.

This is one simple way to check this: puts "f123" to field.
"f123".to_i => 0
"123f".to_i => 123
But in Rails validation, "f123" is validates too.

Michael

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails- [email protected]. To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to