Download the PHP package gmarsano/chilean-phone-tool without Composer
On this page you can find all versions of the php package gmarsano/chilean-phone-tool. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package chilean-phone-tool
🇨🇱 Chilean Phone Tool ☎️
Introduction
A PHP composer package to work with Chilean 🇨🇱 phone numbers.
Features
- Parsing
- Get prefix
- Validation
- Formatting
- Factory
Contents
- Introduction
- Features
- Contents
- Install
- Requirements
- Usage
- Set a phone number.
parse
setPhone
- Validation
validate
errors
andmessages
- Error messages
- Ignore prefix validation
fix
andluckyFix
- Formatting
format
- Choosing format
- Factory
- Aliases
- Set a phone number.
- Inspired by
- License
Install
Requirements
- PHP >= 7.3
Usage
Set a phone number.
parse
Usually you may want to take a phone in any format, check if it's valid and
bring it to the desired format. Use parse
to set the number, if that the case.
If you parse a valid number you can get the number and prefix just calling these:
Clean an invalid input (use quiet
to prevent validation exceptions):
setPhone
Sometimes you just want to know if an input value is a valid phone number
without clean or make any changes on it before validation. It's time to use
setPhone
:
Validation
validate
Use validate
to check if it is a valid number. An invalid number will throw an
exception with a message giving information about the reasons.
The features of this tool make sense on a valid phone. This is why by default it
works with exceptions. But you can use quiet
to avoid this behavior, but be
careful, if you try to get or format an invalid number you will get the original
digits or value depending on the case.
errors
and messages
They allow to obtain an array with validation messages if quiet
has been used.
They may look like aliases, but there is a little difference:
- with
errors
you get a list of the validation messages with error codes as keys. - with
messages
you only get the messages.
Error messages
code | message |
---|---|
2 | Empty digits count. |
3 | Invalid phone number format. |
4 | Invalid country code. |
5 | Invalid prefix. |
6 | Invalid phone number. |
Ignore prefix validation
To avoid prefix validation use ignorePrefix
:
fix
and luckyFix
Tries to set a valid phone from original input.
Use getOld
to get original value.
Sometimes the inputs may lack the Santiago prefix (2). Use luckFix
to fix and
try to guess if the missing prefix can be fixed.
As you can see, after fix, validation can be true. If you need to check if original was modified because it was invalid, then you can count errors.
Formatting
format
Use format
on a valid phone to get the value in standard numbering format.
Choosing format
Give format
method the desired format as an argument.
format |
example |
---|---|
FormatterInterface::STANDARD_FORMAT | +56 9 87-654-321, +56 75 7-654-321 |
FormatterInterface::PREFIX_FORMAT | (9) 87-654-321, (75) 7-654-321 |
FormatterInterface::DIGITS_FORMAT | 56987654321, 56757654321 |
FormatterInterface::NUMBER_DIGITS_FORMAT | 987654321, 757654321 |
Factory
You can generate a valid phone number using Phone Tool:
Make multiple numbers giving a count as argument to make
method.
You can use the unique
, cellPhone
, landLine
or prefix
modifiers to make
unique numbers, cell phone, landline (red fija), or set a valid prefix manually.
Use format
(check choosing format) modifier to give
desired format to numbers.
Aliases
methods | aliases |
---|---|
get() | number |
get(true) | fullNumber |
getPrefix | prefix |
validate | isValid |
Inspired by
License
MIT License
Copyright (c) 2021 gmarsano