PHPackages                             ap-lib/validator-us - 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. ap-lib/validator-us

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

ap-lib/validator-us
===================

033PHP

Since Aug 17Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/ap-lib/validator-us)[ Packagist](https://packagist.org/packages/ap-lib/validator-us)[ RSS](/packages/ap-lib-validator-us/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

AP\\Validator\\US
=================

[](#apvalidatorus)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A set of US-specific input validators, ensuring proper formatting and sanitization.

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

[](#installation)

```
composer require ap-lib/validator-us
```

Modules
-------

[](#modules)

- **CitySanitizes** - Ensures valid US city names, removing invalid characters and normalizing formatting.
- **NameSanitizes** - Sanitizes personal names, ensuring proper structure while preserving necessary characters.

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Getting started
---------------

[](#getting-started)

### Sanitizing a City

[](#sanitizing-a-city)

```
use AP\Validator\US\CitySanitizes;

$city = "  New!! York--";
$validator = new CitySanitizes();

if ($validator->validateString($city) === true) {
    echo "Sanitized City: " . $city; // Output: "New York"
} else {
    echo "Invalid city name!";
}
```

### Sanitizing a Name

[](#sanitizing-a-name)

```
use AP\Validator\US\NameSanitizes;

$name = "  O``Brien--";
$validator = new NameSanitizes();

if ($validator->validateString($name) === true) {
    echo "Sanitized Name: " . $name; // Output: "O'Brien"
} else {
    echo "Invalid name!";
}
```

### Sanitizing an Address

[](#sanitizing-an-address)

```
use AP\Validator\US\AddressSanitizes;

$address = "  400 Elm St. #10B  ";
$validator = new AddressSanitizes();

if ($validator->validate($address) === true) {
    echo "Sanitized Address: " . $address; // Output: "400 Elm St. #10B"
} else {
    echo "Invalid address!";
}
```

### Validating a Phone Number

[](#validating-a-phone-number)

```
use AP\Validator\US\PhoneSanitizer;

$validator = new PhoneSanitizer();

# just sanitize convert to int if possible
$phone = "12 - 34";
if ($validator->sanitize($phone) === true) {
    echo "Sanitized Phone: " . $phone; // Output: 1234
} else {
    echo "Invalid phone number!";
}

// sanitize + validation
$phone = "(223) 456-7890";
if ($validator->validate($phone) === true) {
    echo "Sanitized and Valid Phone: " . $phone; // Output: 2234567890
} else {
    echo "Invalid phone number!";
}
```

### Validating an SSN

[](#validating-an-ssn)

```
use AP\Validator\US\SSNSanitizer;

$validator = new SSNSanitizer();

# just sanitize convert to int if possible
$ssn = "1234";
if ($validator->sanitize($ssn) === true) {
    echo "Sanitized SSN: " . $ssn; // Output: 1234
} else {
    echo "Invalid SSN!";
}

// sanitize + validation
$ssn = "123-45-6789";
if ($validator->validate($ssn) === true) {
    echo "Sanitized and Valid SSN: " . $ssn; // Output: 123456789
} else {
    echo "Invalid SSN!";
}
```

###  Health Score

19

—

LowBetter than 12% of packages

Maintenance45

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1215fe5ecc9ba0ab1c730d3c992125cf6ebf460562e66be71ebae127789d465a?d=identicon)[AntonPanfilov](/maintainers/AntonPanfilov)

---

Top Contributors

[![anton-panfilov](https://avatars.githubusercontent.com/u/1083546?v=4)](https://github.com/anton-panfilov "anton-panfilov (9 commits)")

### Embed Badge

![Health badge](/badges/ap-lib-validator-us/health.svg)

```
[![Health](https://phpackages.com/badges/ap-lib-validator-us/health.svg)](https://phpackages.com/packages/ap-lib-validator-us)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k882.5M1.0k](/packages/webmozart-assert)[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k479.5M567](/packages/composer-semver)[respect/validation

The most awesome validation engine ever created for PHP

5.9k36.6M349](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k34.5M83](/packages/propaganistas-laravel-phone)[laminas/laminas-escaper

Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs

21986.9M118](/packages/laminas-laminas-escaper)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.2M67](/packages/swaggest-json-schema)

PHPackages © 2026

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