PHPackages                             coroq/form-country-jp - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. coroq/form-country-jp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

coroq/form-country-jp
=====================

v1.0.1(5mo ago)02MITPHPPHP ^8.0

Since Nov 21Pushed 5mo agoCompare

[ Source](https://github.com/coroq-com/coroq-form-country-jp)[ Packagist](https://packagist.org/packages/coroq/form-country-jp)[ RSS](/packages/coroq-form-country-jp/feed)WikiDiscussions main Synced 1mo ago

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

Coroq Form Country JP
=====================

[](#coroq-form-country-jp)

Japan country-specific form inputs for [coroq/form](https://github.com/ozami/coroq-form).

Features
--------

[](#features)

- **PostalCodeInput** - Japanese postal code (郵便番号) validation and normalization
- **TelInput** - Japanese telephone number (電話番号) validation and normalization
- **PrefectureCodeSelect** - 47 Japanese prefectures selection (2-digit codes: 01-47)
- **PrefectureSelect** - 47 Japanese prefectures selection (prefecture names)
- **ErrorMessages** - Japanese error messages

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

[](#installation)

```
composer require coroq/form-country-jp
```

Requires PHP ^8.0, coroq/form ^3.0

PostalCodeInput
---------------

[](#postalcodeinput)

Validates Japanese postal codes with configurable output format.

```
use Coroq\Form\Form;
use Coroq\Form\Country\Jp\FormItem\PostalCodeInput;

class AddressForm extends Form {
    public readonly PostalCodeInput $postalCode;

    public function __construct() {
        $this->postalCode = new PostalCodeInput();
    }
}

$form = new AddressForm();
$form->setValue(['postalCode' => '123-4567']);

if ($form->validate()) {
    echo $form->postalCode->getValue();        // "1234567"
    echo $form->postalCode->getPostalCode();   // "1234567" or null
}
```

### Input Formats

[](#input-formats)

Accepts both "1234567" and "123-4567" formats. Normalizes full-width characters and various dash types (－, −, ー).

```
$postal = new PostalCodeInput();

$postal->setValue('123-4567');     // "1234567"
$postal->setValue('１２３４５６７'); // "1234567"
$postal->setValue('123−4567');     // "1234567"
$postal->setValue('  123 4567  '); // "1234567"
```

### Output Format

[](#output-format)

Default is without hyphen. Use `setWithHyphen(true)` for hyphenated output:

```
$postal = (new PostalCodeInput())->setWithHyphen(true);
$postal->setValue('1234567');
echo $postal->getValue();  // "123-4567"
```

TelInput
--------

[](#telinput)

Validates Japanese domestic telephone numbers (10-11 digits starting with 0).

```
use Coroq\Form\Country\Jp\FormItem\TelInput;

$tel = new TelInput();
$tel->setValue('090-1234-5678');

if ($tel->validate()) {
    echo $tel->getValue();    // "09012345678"
    echo $tel->getTel();      // "09012345678" or null
}
```

### Input Formats

[](#input-formats-1)

Accepts 10-11 digit numbers starting with 0. Normalizes full-width characters, hyphens, and whitespace.

```
$tel = new TelInput();

$tel->setValue('090-1234-5678');   // "09012345678"
$tel->setValue('０９０１２３４５６７８'); // "09012345678"
$tel->setValue('  090 1234 5678  '); // "09012345678"
```

### With Hyphen Mode

[](#with-hyphen-mode)

Use `setWithHyphen(true)` to require hyphens in input (asymmetric validation).

```
$tel = (new TelInput())->setWithHyphen(true);
$tel->setValue('090-1234-5678');  // Valid, keeps hyphens
$tel->setValue('09012345678');     // Invalid - requires hyphens
```

PrefectureSelect
----------------

[](#prefectureselect)

Select input for all 47 Japanese prefectures. Values and labels are both prefecture names.

```
use Coroq\Form\Country\Jp\FormItem\PrefectureSelect;

$prefecture = new PrefectureSelect();
$prefecture->setValue('東京都');

if ($prefecture->validate()) {
    echo $prefecture->getValue();        // "東京都"
    echo $prefecture->getPrefecture();   // "東京都" or null
}
```

### Empty Option Label

[](#empty-option-label)

By default, an empty option with an empty label is added at the top. You can customize the label:

```
$prefecture = (new PrefectureSelect())->setEmptyOptionLabel('選択してください');
// First option will be: '' => '選択してください'
```

PrefectureCodeSelect
--------------------

[](#prefecturecodeselect)

Select input for all 47 Japanese prefectures using JIS X 0401 codes (01-47). Values are 2-digit codes, labels are prefecture names.

```
use Coroq\Form\Country\Jp\FormItem\PrefectureCodeSelect;

$prefecture = new PrefectureCodeSelect();
$prefecture->setValue('13');  // Tokyo

if ($prefecture->validate()) {
    echo $prefecture->getValue();        // "13"
    echo $prefecture->getPrefecture();   // "東京都"
}
```

### Empty Option Label

[](#empty-option-label-1)

Same as PrefectureSelect, you can customize the empty option label:

```
$prefecture = (new PrefectureCodeSelect())->setEmptyOptionLabel('選択してください');
```

Error Messages
--------------

[](#error-messages)

```
use Coroq\Form\ErrorMessageFormatter;
use Coroq\Form\Country\Jp\ErrorMessages;

$formatter = new ErrorMessageFormatter();
$formatter->setMessages(ErrorMessages::get());

if ($form->postalCode->hasError()) {
    echo $formatter->format($form->postalCode->getError());
    // "正しい郵便番号を入力してください"
}

if ($form->tel->hasError()) {
    echo $formatter->format($form->tel->getError());
    // "正しい電話番号を入力してください"
}
```

Testing
-------

[](#testing)

```
composer test
composer coverage       # HTML coverage report → coverage/
composer coverage-text  # Text coverage report
```

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance73

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Every ~21 days

Total

2

Last Release

150d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/addac0ea12d91786ce888c91ef7de6525bc17252c702cd7e48fe64ab547c012e?d=identicon)[ozami](/maintainers/ozami)

---

Top Contributors

[![ozami](https://avatars.githubusercontent.com/u/170309?v=4)](https://github.com/ozami "ozami (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/coroq-form-country-jp/health.svg)

```
[![Health](https://phpackages.com/badges/coroq-form-country-jp/health.svg)](https://phpackages.com/packages/coroq-form-country-jp)
```

PHPackages © 2026

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