PHPackages                             dhalsted/sms-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. dhalsted/sms-utils

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

dhalsted/sms-utils
==================

Validate SMS numbers using libphonenumber and Twilio

0.0.0(8y ago)034MITPHPPHP &gt;=5.3.0

Since Sep 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dhalsted/sms-utils)[ Packagist](https://packagist.org/packages/dhalsted/sms-utils)[ RSS](/packages/dhalsted-sms-utils/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (2)Used By (0)

sms-utils
=========

[](#sms-utils)

sms-utils contains methods I've found useful for handling text messaging. I primarily use Twilio for this but eventually I hope to add support for other vendors.

The first version contains code to validate that a string represents a valid SMS number--something that Twilio won't choke on. This means it must meet certain formatting restrictions and, in addition, must be a number for a text-capable phone (ie, not a landline). The rules for this are complicated. The SMS Validator class will take a string, check that it can be parsed as a phone number, check that it is not a landline, and return a version of the number formatted for use with Twilio. It can handle numbers from different countries and regions. Format validation is handled through Google's libphonenumber and the check for SMS capability is run through Twilio.

Note that you'll need Twilio API credentials to use the Validator.

Installation
------------

[](#installation)

Clone or download the repository. Then

```
composer install

```

To run tests, first copy .env.example to .env and then run

```
composer test

```

This will run a set of tests that don't require Twilio credentials. To run a more complete set of tests, fill in .env with Twilio credentials and some sample phone numbers, and then do

```
composer test

```

again.

Quickstart
----------

[](#quickstart)

To use the validator, do something like

```
php cli_validate.php '(444) 111-2222'

```

where (444) 111-2222 is a valid US landline. You should get

```
Not mobile exception: Number does not appear to be a mobile number

```

Then try it with a mobile number. In this case, you'll get back

```
+14441112222

```

To call the SMSValidator class in your own code, just do

```
$sv = new \Dhalsted\SMS\SMSValidator(TWILIO_SID, TWILIO_TOKEN);
$validated_number = $sv->validateMobileNumber($phone_number, $country_code);

```

By default, the Validator checks whether the submitted phone number is a mobile or VoIP number. If you want to check specifically for one or the other, do something like this:

```
$validated_number = $sv->validateMobileNumber($phone_number, $country_code, array('mobile'));

```

SMSValidator throws several kinds of exceptions which can help your users understand why a number will not work for texts.

- SMSTwilioMisconfigException (code 20100) occurs if missing, incomplete or invalid Twilio credentials are submitted.
- SMSBadNumberException (code 20101) occurs if the data submitted for a phone number can't be parsed or is incomplete. Submitting a non-existent country or region code, a string that cannot be parsed ("phone number 888 555 1212" instead of "888 555 1212"), or a truncated number will raise this exception.
- SMSNotMobileException (code 20102) occurs if a number is submitted that is not a valid type, by default either mobile or VoIP.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3196d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/314109?v=4)[David Halsted](/maintainers/dhalsted)[@dhalsted](https://github.com/dhalsted)

---

Top Contributors

[![dhalsted](https://avatars.githubusercontent.com/u/314109?v=4)](https://github.com/dhalsted "dhalsted (14 commits)")

---

Tags

phpcomposerlibphonenumbertwilio

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dhalsted-sms-utils/health.svg)

```
[![Health](https://phpackages.com/badges/dhalsted-sms-utils/health.svg)](https://phpackages.com/packages/dhalsted-sms-utils)
```

###  Alternatives

[bitrix24/b24phpsdk

An official PHP library for the Bitrix24 REST API

10239.4k5](/packages/bitrix24-b24phpsdk)[lakshmajim/twilio

SMS sending using Twilio

328.7k](/packages/lakshmajim-twilio)[stuyam/laravel-phone-validator

A phone validator for Laravel using the free Twilio phone lookup service.

2861.7k](/packages/stuyam-laravel-phone-validator)[ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

1130.0k](/packages/ellisio-laravel-phone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
