Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/message/PhabricatorPhoneNumber.php
- This file was added.
<?php | |||||
final class PhabricatorPhoneNumber | |||||
extends Phobject { | |||||
private $number; | |||||
public function __construct($raw_number) { | |||||
$number = preg_replace('/[^\d]+/', '', $raw_number); | |||||
if (!preg_match('/^[1-9]\d{1,14}\z/', $number)) { | |||||
throw new Exception( | |||||
amckinley: Where did this regex come from? A few minutes of digging for validating of E.123 numbers points… | |||||
Done Inline ActionsI expect this will be refined a lot, but it's more-or-less from the Twilio docs here: epriestley: I expect this will be refined a lot, but it's more-or-less from the Twilio docs here:
https… | |||||
pht( | |||||
'Phone number ("%s") is not in a recognized format.', | |||||
$raw_number)); | |||||
} | |||||
$this->number = $number; | |||||
} | |||||
public function toE164() { | |||||
return '+'.$this->number; | |||||
} | |||||
} |
Where did this regex come from? A few minutes of digging for validating of E.123 numbers points to this O'Reilly suggestion: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s03.html