While I am guessing you've already solved your problem (because it was related to your database schema) I'll still answer your regular expression questions:

The number returned is the position of the string where your regular expression matches, 0 is the start of the string.
nil means no matches were found.

In the case of your regular expression you'd only ever get 0 or nil because your regular expression requires the start of the string to match.

On 18-2-2011 14:18, Victor S wrote:
I have tested a simpler version and noticed this:

ruby-1.9.2-p136 :010 > /^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/ =~ "1234567890"
 => 0
ruby-1.9.2-p136 :011 > /^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/ =~ "(123)4567890"
 => 0
ruby-1.9.2-p136 :012 > /^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/ =~ "(123) 456-7890"
 => 0
ruby-1.9.2-p136 :013 > /^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/ =~ "(123)3456-7890"
 => nil
ruby-1.9.2-p136 :014 > /^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/ =~ "(123)-456-7890"
 => 0
ruby-1.9.2-p136 :015 > /^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/ =~ "(123) 456-7890 smurf"
 => nil
ruby-1.9.2-p136 :016 >


does 0 mean pass? And is then the validated_with not accepting 0 as a pass?
--
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.

--
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