Phone number cleanup in Rails

In: Ruby on Rails

6 Feb 2010

There is practically nothing that cant be done with ruby (hmm… may be a little exaggerating there). Was working on this SMS platform where users can send SMS free without login or registration. The number was to be in the format eg. 233244342123, everything was smooth, i validated for digits on and the users are allowed to SMS up to 10 numbers in a single shot, which means you can do something like 233244566778,233244566777,233244566756 and it will be sent to three recipients.

I wanted to try some random numbers, so I shot up Address book on my Mac and copied a number, i realized it was in the format 233-244-124-660 and I always have to manually cleanup the dashes b4 I sent it. I knew this is going to be a usability issue and that’s not so good, looking at my level.

Well I decided to do a code improvement which will clear any empty spaces, dashes and plus symbols and then return the string as an array of numbers for further checks like restrict the user to 10 numbers only, etc.

Works perfectly like I want it to

Comment Form

About this blog

Just tackling programming nightmares with flares. Sometimes the tactics are smooth sometimes their rough.

Photostream

About Me

1Alfred is a seasoned programmer with over 8 years of experience, CEO of nCodedev Labs, a Ruby evangelist and activist. Loves programming most of the time, spends my free times with his family or trying out something new. He believes in doing more than expected of you and working hard at anything you find your self working on. As he always says, you don't have to take the bull by its horns all the time, you can take it by the tail too and move on to the horns when you stronger.