{"record":{"id":"739dccc3bc87722e","repo":"phacility/phabricator","slug":"phone-number-s-is-not-in-a-recognized-format","errorCode":null,"errorMessage":"Phone number (\"%s\") is not in a recognized format: expected a US number like \"(555) 555-5555\", or an international number like \"+55 5555 555555\".","messagePattern":"Phone number \\(\"(.+?)\"\\) is not in a recognized format: expected a US number like \"\\(555\\) 555-5555\", or an international number like \"\\+55 5555 555555\"\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/metamta/message/PhabricatorPhoneNumber.php","lineNumber":12,"sourceCode":"<?php\n\nfinal class PhabricatorPhoneNumber\n  extends Phobject {\n\n  private $number;\n\n  public function __construct($raw_number) {\n    $number = preg_replace('/[^\\d]+/', '', $raw_number);\n\n    if (!preg_match('/^[1-9]\\d{9,14}\\z/', $number)) {\n      throw new Exception(\n        pht(\n          'Phone number (\"%s\") is not in a recognized format: expected a '.\n          'US number like \"(555) 555-5555\", or an international number '.\n          'like \"+55 5555 555555\".',\n          $raw_number));\n    }\n\n    // If the number didn't start with \"+\" and has has 10 digits, assume it is\n    // a US number with no country code prefix, like \"(555) 555-5555\".\n    if (!preg_match('/^[+]/', $raw_number)) {\n      if (strlen($number) === 10) {\n        $number = '1'.$number;\n      }\n    }\n\n    $this->number = $number;\n  }\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/metamta/message/PhabricatorPhoneNumber.php#L1-L30","documentation":"PhabricatorPhoneNumber strips every non-digit character, then requires the remaining digits to match ^[1-9]\\d{9,14}\\z: 10 to 15 digits with no leading zero. A raw number without a leading '+' whose digits total exactly 10 is assumed to be US and gets '1' prefixed. Any input that does not survive this normalization (too few/many digits, leading zero, empty) throws a plain Exception from the constructor. It is used wherever Phabricator stores or routes SMS phone numbers.","triggerScenarios":"Constructing with a 7-digit local number ('555-1234'); numbers with a leading zero after stripping; empty or purely non-numeric input; numbers longer than 15 digits (e.g. with an extension appended); non-US numbers supplied without a country code.","commonSituations":"SMS mailer integrations (user phone numbers from account settings) fed with placeholder test data; users entering local-format numbers; forms that do not validate before saving, so the failure surfaces later at send/lookup time.","solutions":["Store numbers in E.164 format with a leading '+' (e.g. +15555551234).","For US numbers without '+', include the area code so the digit count is exactly 10.","Trim extension suffixes and formatting noise before constructing PhabricatorPhoneNumber.","Validate at input time (same regex the class uses) so bad data never reaches storage."],"exampleFix":"// before\n$number = new PhabricatorPhoneNumber('555-1234');\n// throws: not in a recognized format\n\n// after\n$number = new PhabricatorPhoneNumber('+1 (555) 555-1234');","handlingStrategy":"validation","validationCode":"// Apply the class's own normalization rules before constructing:\nfunction is_valid_phone_number($raw) {\n  $digits = preg_replace('/[^\\d]+/', '', $raw);\n  return (bool)preg_match('/^[1-9]\\d{9,14}\\z/', $digits);\n}\nif (!is_valid_phone_number($raw)) {\n  // reject at input time with a user-facing message\n}","typeGuard":null,"tryCatchPattern":"try {\n  $number = new PhabricatorPhoneNumber($raw);\n} catch (Exception $ex) {\n  // surface the message to the user and re-prompt for E.164 input\n}","preventionTips":["Store phone numbers in E.164 (+countrycode, 10–15 digits).","Validate at the form/API boundary with the same regex the class uses.","Strip extensions and formatting characters before saving.","Use placeholder test data that is 10+ digits, never '555-1234'."],"tags":["php","phabricator","sms","phone","validation"],"backgroundTag":"phone-number-validation","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}