piyo2 / format-phone-jp
Japanese phone number validator/formatter.
Installs: 5 078
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.4.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Japanese phone number validator/formatter.
Usage
Basic
use piyo2\format\PhoneJP; $f = new PhoneJP(); // Valid number $f->validate('0120444444'); // => true $f->format('0120444444'); // => '0120-444-444' $f->formatIfValid('0120444444'); // => '0120-444-444' // Invalid number $f->validate('0127-12-3456'); // => false $f->format('0127-12-3456'); // => '0127-12-3456' (= input value) $f->formatIfValid('0127-12-3456'); // => null
Force prefix
$f = new PhoneJP(); $f->format('120444444'); // => '120-444-444' $f->format('0120444444'); // => '0120-444-444' $f->format('+81120444444'); // => '+81 120-444-444' $f->setPrefixMode(PhoneJP::PREFIX_FORCE_DOMESTIC); $f->format('120444444'); // => '0120-444-444' $f->setPrefixMode(PhoneJP::PREFIX_FORCE_COUNTRY); $f->format('120444444'); // => '+81 120-444-444'
Set delimiter
$f = new PhoneJP(); $f->setDelimiter(' '); $f->format('0120444444'); // => '0120 444 444' $f->setDelimiter('-'); $f->setCountryPrefixDelimiter('-'); $f->format('+81120444444'); // => '+81-120-444-444'
Data source
- 総務省|電気通信番号制度|市外局番の一覧 (2022-03-01)