Skip to content

Commit

Permalink
regex
Browse files Browse the repository at this point in the history
- added preg_match for sender name
  • Loading branch information
Loafer19 committed Jul 20, 2021
1 parent 113f13e commit dc0332c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/GatewayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Loafer\GatewayApi;


use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Subscriber\Oauth\Oauth1;

use InvalidArgumentException;

class GatewayApi
{
private $client;
Expand Down Expand Up @@ -39,8 +40,11 @@ public function __construct()

public function setSenderName(string $name)
{
// TODO: Up to 11 alphanumeric characters, or 15 digits
$this->sender_name = substr($name, 0, 15);
if (!preg_match("/^[[:alnum:] ]{1,11}$|^[[:digit:]]{1,15}$/", $name, $matches)) {
throw new InvalidArgumentException('The sender\'s name must contain up to 11 alphanumeric characters or up to 15 digits, ' . $name);
};

$this->sender_name = $name;

return $this;
}
Expand Down

0 comments on commit dc0332c

Please sign in to comment.