https://github.com/nightapes/ngx-phone-validators
angular validator for phone numbers
https://github.com/nightapes/ngx-phone-validators
angular angular2 angular7 google-libphonenumber phone validators
Last synced: 3 months ago
JSON representation
angular validator for phone numbers
- Host: GitHub
- URL: https://github.com/nightapes/ngx-phone-validators
- Owner: Nightapes
- License: mit
- Created: 2018-05-22T13:54:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T04:14:31.000Z (over 2 years ago)
- Last Synced: 2025-06-30T15:49:51.972Z (3 months ago)
- Topics: angular, angular2, angular7, google-libphonenumber, phone, validators
- Language: TypeScript
- Homepage:
- Size: 1.01 MB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ngx-phone-validators
[](https://david-dm.org/nightapes/ngx-phone-validators)
An implementation of various angular validators for Angular 2+.
# List of validators
1. Phone
# Install
`npm install ngx-phone-validators --save`
## [Angular CLI](https://github.com/angular/angular-cli)
No config needed
## [Angular Seed](https://github.com/mgechev/angular-seed)
Add following to `project.config.ts`
```ts
let additionalPackages: ExtendPackages[] = [
{
name: "google-libphonenumber",
path: "node_modules/google-libphonenumber/dist/libphonenumber.js"
},
{
name: "ngx-phone-validators",
path:
"node_modules/ngx-phone-validators/bundles/ngx-phone-validators.umd.min.js"
}
];this.addPackagesBundles(additionalPackages);
```For AOT add
```ts
this.ROLLUP_NAMED_EXPORTS = [
...this.ROLLUP_NAMED_EXPORTS,
{
"node_modules/google-libphonenumber/dist/libphonenumber.js": [
"PhoneNumberUtil"
]
}
];
```## Install
```
npm install ngx-phone-validators --save
```## How to use [model driven]
needs: `ReactiveFormsModule`
### Phones
```ts
import {PhoneValidators} from 'ngx-phone-validators'...
phone: FormControl = new FormControl('', Validators.compose([
PhoneValidators.isValidRegionCode,
PhoneValidators.isPhoneNumber('DE'),
PhoneValidators.isPossibleNumberWithReason('DE'),
]));
``````
regionCode: FormControl = new FormControl('', PhoneValidators.isValidRegionCode);
phoneNumber: FormControl = new FormControl('', PhoneValidators.isPhoneNumber('DE'));
possiblePhoneNumber: FormControl = new FormControl('', PhoneValidators.isPossibleNumberWithReason('DE'));
```## How to use [template driven]
needs `FormsModule and PhoneValidatorsModule`
```ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { PhoneValidatorsModule } from "ngx-phone-validators";import { AppComponent } from "./app.component";
@NgModule({
imports: [BrowserModule, FormsModule, PhoneValidatorsModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
```### Phone
```html
Invalid region code
No valid phone number```
### Country Code
```html
Invalid region code```
### Possible phone
```html
Invalid region code
No valid phone number
Phone number too long
Phone number too short```
Get the complete changelog here: https://github.com/Nightapes/ngx-phone-validators/releases