Sorry, made a mistake, the result of number_to_phone would be (123)
456-7890 (I missed the 0).

And about the number of digits, I said \d{10} makes sure the string
contains only 10 digits. What I meant is that the string will have to
contain a total of 10 digits, no more, no less.

Pepe

On Mar 2, 10:53 pm, pepe <[email protected]> wrote:
> I'm not sure the type of validation you need on the field. This is
> something simple I did for an application I wrote:
>
>     phone =~ /^\d{10}$/ && phone.to_i >= 999999999
>
> This will make sure that the string contains only 10 digits (/^\d
> {10}$/) and that the 10 digits are miningful or the number doesn't
> start with a 0 (>= 999999999).
>
> About the formatting of the string, rails has tons of helpers, and the
> one you're looking for is number_to_phone:
>
> <%= number_to_phone(1234567890, :aea_code => true, :delimiter => ' ')
> %> # (123) 456-789
>
> On Mar 2, 2:52 am, cool <[email protected]> wrote:
>
> > Guys,
>
> >      I have a text field and the name is phone
> >     I used to enter contact number.
> >    In the new form when i enter 10 digit number like "1234567890" it
> > is displaying 1234567890
> >   I want to display like in US format automatically like "(123)
> > 456-7890".
> >    I need to provide validation for that field also.
> > Can u help me how can i do that.
> >   Very badly i need a help. i am struck with this issue......
--~--~---------~--~----~------------~-------~--~----~
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