Closed naotokui closed 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.
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.
Yes, you are right about that format check. I will see about adding a validation method. Thanks.
An update has been committed. Please see the update code and the update README file for details about the new method for validation.
Wow! Thanks a lot!
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