On Jun 9, 10:53 am, Colin Law <[email protected]> wrote:
> 2009/6/9 Newb Newb <[email protected]>:
>
>
>
> > i use this code to validate the phone field.it should have only numbers.
> > but it also accepts alphapets with numbers.it should not accept other
> > than numkbers
> > below is my code i use.
> > errors.add(:phone_code, "*please enter valid phone number") unless
> > self.phone_code =~/[0-9]/
>
> That will match if there is at least one number in the string. I think
> you need something like
> /\A[0-9]*\z/
> or
> /\A\d*\z/

if you are going to use a regexp you might as well use
validates_format_of rather than doing it yourself

Fred


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