Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Better phone-number-parsing
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
zyberspace committed May 10, 2015
1 parent 3d5d0a4 commit 8f5f94f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/Zyberspace/Telegram/Cli/AbstractClientCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public function msg($peer, $msg)
/**
* Adds a user to the contact list
*
* @param int|string $phoneNumber The phone-number of the new contact, needs to be a telegram-user.
* Can start with or without '+'.
* @param string $phoneNumber The phone-number of the new contact, needs to be a telegram-user.
* Every char that is not a number gets deleted, so you don't need to care about spaces,
* '+' and so on.
* @param string $firstName The first name of the new contact
* @param string $lastName The last name of the new contact
*
Expand All @@ -75,10 +76,10 @@ public function msg($peer, $msg)
*/
public function addContact($phoneNumber, $firstName, $lastName)
{
if (is_string($phoneNumber) && $phoneNumber[0] === '+') {
$phoneNumber = substr($phoneNumber, 1);
$phoneNumber = preg_replace('%[^0-9]%', '', (string) $phoneNumber);
if (empty($phoneNumber)) {
return false;
}
$phoneNumber = (int) $phoneNumber;

return $this->exec('add_contact ' . $phoneNumber . ' ' . $this->escapeStringArgument($firstName)
. ' ' . $this->escapeStringArgument($lastName));
Expand Down

0 comments on commit 8f5f94f

Please sign in to comment.