dniccum / phone-number
A Laravel Nova phone number field with input masking and validation support.
                                    Fund package maintenance!
                                                                            
                                                                                                                                        dniccum
                                                                                    
                                                                
Installs: 373 277
Dependents: 0
Suggesters: 0
Security: 0
Stars: 71
Watchers: 2
Forks: 18
Open Issues: 7
pkg:composer/dniccum/phone-number
Requires
- php: ^8.1
- laravel/framework: ^10.34|^11.0|^12.0
- laravel/nova: ^5.0
- propaganistas/laravel-phone: ^5.2
- dev-master
- v3.0.2
- v3.0.1
- v3.0.0
- v2.3.1
- v2.3.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6.1
- v1.0.6
- v1.0.5
- 1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/npm_and_yarn/sha.js-2.4.12
- dev-dependabot/npm_and_yarn/cipher-base-1.0.6
- dev-dependabot/npm_and_yarn/pbkdf2-3.1.3
- dev-dependabot/npm_and_yarn/http-proxy-middleware-2.0.9
This package is auto-updated.
Last update: 2025-10-21 16:23:30 UTC
README
A Laravel Nova field to format using a dynamic input mask and additional phone number validation.
NOTE: This field utilizes Propaganistas / Laravel-Phone package for validation.
Installation
To install this tool, use the installation code below:
composer require dniccum/phone-number
Code
To use the field, add the following code to your Nova resource. As this is a field, all of the default field properties can be applied.
use Dniccum\PhoneNumber\PhoneNumber; PhoneNumber::make('Phone Number')
Options
To support multiple types and formats of phone numbers, this field has multiple methods for input masking and validation that are available.
Defaults
| Method/Options | Default | 
|---|---|
| format | string: '(###) ###-####' | 
| placeholder | string: '[Name of Field]' | 
| useMaskPlaceholder | boolean: false | 
| country | string: 'US' | 
| countries | string[]: ['US'] | 
| disableValidation | boolean: false | 
| linkOnIndex | boolean: false | 
| linkOnDetail | boolean: false | 
format
PhoneNumber::make('Phone Number') ->format('###-###-####')
Type: string
Default: (###) ###-####
This is the value that the javascript controlling the input mask will use define it's values; and depending the field's configuration the placeholder text. To indicate numbers, use the hash (#) symbol.
Note: Other types of content can be included within this input like an phone extension:
PhoneNumber::make('Phone Number') ->format('###-###-#### ext ####')
However the built-in phone number validation will FAIL as this is technically an invalid phone number. To prevent the validation from failing, turn off the phone number validation like so:
PhoneNumber::make('Phone Number') ->format('###-###-####') ->disableValidation()
placeholder
PhoneNumber::make('Phone Number') ->placeholder('Personal Home Number')
Type: string
Default: [Name of the Field]
If you would like to override the default placeholder supplied by Nova, which is the name of field, user a simple string.
Note: If you are telling the input to override the placeholder by using the input's mask with the useMaskPlaceholder method, this will not work.
useMaskPlaceholder
PhoneNumber::make('Phone Number') ->useMaskPlaceholder()
Type: boolean
Default: false
This will tell the field to replace the input's defined placeholder with the input mask from the ->format() method.
country
PhoneNumber::make('Phone Number') ->country('CA')
Type: string
Default: US
This tells the field what type of phone number validation to use. To define a type of validation, define a ISO 3166-1 alpha-2 compliant country code.
You can only define one country here. If you would like to define more than one, please see the ->countries() method.
NOTE: This field utilizes Propaganistas / Laravel-Phone package for validation.
countries
PhoneNumber::make('Phone Number') ->countries(['US', 'CA'])
Type: string[]
Default: US
If you would like to define more than one country to validate against, define string-based array of ISO 3166-1 alpha-2 compliant country codes.
NOTE: This field utilizes Propaganistas / Laravel-Phone package for validation.
linkOnIndex
PhoneNumber::make('Phone Number') ->linkOnIndex()
Type: boolean
Default: false
Render's the phone number as a clickable link on the index view.
linkOnDetail
PhoneNumber::make('Phone Number') ->linkOnDetail()
Type: boolean
Default: false
Render's the phone number as a clickable link on the detail view.
Credits
License
The MIT License (MIT). Please see License File for more information.

