Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable, Pipe } from "@angular/core";
- @Pipe({
- name: "phone"
- })
- export class PhonePipe {
- transform(tel, args) {
- var value = tel
- .toString()
- .replace(/ /g, "");
- if (value.length <= 3) {
- value = value.replace(/^(\d{0,2})/, "($1)");
- } else if (value.length <= 10) {
- value = value.replace(/^(\d{0,2})(\d{0,4})(\d{0,4})/, "($1) $2-$3");
- } else {
- value = value.replace(/^(\d{0,2})(\d{0,5})(\d{0,4})/, "($1) $2-$3");
- }
- return value;
- }
- }
Add Comment
Please, Sign In to add comment