You have unlimited access as a PRO member
You are receiving a free preview of 3 lessons
Your free preview as expired - please upgrade to PRO
Contents
Recent Posts
- Object Oriented Programming With TypeScript
- Angular Elements Advanced Techniques
- TypeScript - the Basics
- The Real State of JavaScript 2018
- Cloud Scheduler for Firebase Functions
- Testing Firestore Security Rules With the Emulator
- How to Use Git and Github
- Infinite Virtual Scroll With the Angular CDK
- Build a Group Chat With Firestore
- Async Await Pro Tips
Angular Phone Number Validation and E164 Formatting
written by Jeff DelaneyIn this snippet, I provide examples of handling phone numbers in Angular. If you’re working with a phone API, such as Twilio, you will need to covert numbers to E164.
Template Driven Style
First, let’s model the data and create a method for E164 formatting.
export class PhoneNumber { |
In the component TypeScript.
@Component({ |
In the HTML
<label for="phone">Phone Number</label><br> |
Reactive Style
Now let’s do the same basic thing with a reactive form.
export class PhoneComponent implements OnInit { |
And in the HTML
<form [formGroup]="numberForm" (ngSubmit)="doSomething()" novalidate> |