rmaddy / RMPhoneFormat

RMPhoneFormat provides a simple to use class for formatting phone numbers in iOS apps. The formatting should replicate what you would see in the Contacts app for the same phone number.
266 stars 61 forks source link

Validation? #1

Closed naotokui closed 11 years ago

naotokui commented 11 years ago

Good work! This is very interesting and useful class.

One quick question: How can I check if a string is valid as a phone number?

I know how to format, but couldn't find how to validate.

Thanks

rmaddy commented 11 years ago

If you format a phone number and get back the same string, then you know it is valid. But it depends on what validation you want done. For example, in the US, many formatted phone numbers come back as "(123) 456-7890". If I pass in that value for formatting, the formatted value is the same so you know it is valid. But if you want to consider "1234567890" or "123-456-7890" as valid, then I would need to add a method for validation.

naotokui commented 11 years ago

Thanks for your quick comment.

When you format "(123) 456", you get the same "(123) 456", right? But it's obviously too short and not valid as a phone number.

Yes, I'd like to consider both "1234567890" and "123-456-7890" as valid.

On Jan 11, 2013, at 11:26 AM, rmaddy notifications@github.com wrote:

If you format a phone number and get back the same string, then you know it is valid. But it depends on what validation you want done. For example, in the US, many formatted phone numbers come back as "(123) 456-7890". If I pass in that value for formatting, the formatted value is the same so you know it is valid. But if you want to consider "1234567890" or "123-456-7890" as valid, then I would need to add a method for validation.

— Reply to this email directly or view it on GitHub.

rmaddy commented 11 years ago

Yes, you are right about that format check. I will see about adding a validation method. Thanks.

rmaddy commented 11 years ago

An update has been committed. Please see the update code and the update README file for details about the new method for validation.

naotokui commented 11 years ago

Wow! Thanks a lot!