Is there a way to identify legitimate contacts and phone numbers within an Android application using Javascript or Typescript?

I am developing an Android app where I need to show a list of contacts and specify if they are part of the app's network. However, my goal is to only display valid contacts while excluding unwanted ones such as toll-free numbers or data balance check services. Ideally, I would like to focus on showing contacts who are smart phone users only.

To achieve this, I am currently filtering out unwanted contacts based on certain rules such as: 1) Excluding numbers starting with 1-800.. 2) Ensuring that the formatted number is exactly 10 digits

My questions are: Q1. Is there a more efficient method to accomplish this task? Q2. What are some effective rules that can be implemented for this purpose?

Answer №1

If you're looking to extract specific patterns from text, consider using a Regular Expression.

For those new to RegEx, understanding them is crucial for the functionality of most web applications.

If you're short on time, there are numerous pre-made expressions available in this extensive library.

However, mastering the art of writing RegEx is highly recommended.

Here are some examples:


/[0-9]+

This expression will match any single digit between 0 and 9, with at least one character required.

23823 - matched
9382 - matched
2 - matched
foo - not matched


/\b\d{3}[-.]?\d{3}[-.]?\d{4}\b

A simple RegEx pattern designed to identify North American phone numbers.

0123456789 - matched
555.123.4567 - matched

RegEx allows for a wide range of complexity - the example provided here is quite basic and may not cover all possible scenarios.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining tuples with their corresponding data types

Trying to define a new type: type Union = [1, "one"] | [1, "first"] | [2, "two"] type GetTuple<T, U> = Extract<T, [U, ...unknown[]]>; type ObjectFromUnion<T extends Union[0] = Union[0]> = { number: T, word: ?? } Looking to utiliz ...

Property 'text' is not found on type '{} | Response' in Angular/Node

After making changes to my angular project's package.json by downgrading from version 4.2.4 to 4.1.3 and then upgrading back to 4.2.4, I encountered an error while building the project: $ ng build Your global Angular CLI version (1.5.0) is greater ...

Tips for accessing an API and setting up data mapping for a data table in nuxt.js

I desperately need assistance. I have been struggling with this issue for a while now, but all my attempts have ended in failure. My objective is to retrieve API data that corresponds to an array containing name, id, and email, and then display this inform ...

Unable to activate parameter function until receiving "yes" confirmation from a confirmation service utilizing a Subject observable

Currently, I am working on unit tests for an Angular application using Jasmine and Karma. One of the unit tests involves opening a modal and removing an item from a tree node. Everything goes smoothly until the removeItem() function is called. This functi ...

Creating a dynamic form with Angular 7 using ngFor and ngModel, incorporating validation through ngFrom attribute

I am currently working on developing an Angular input form that resembles a table. Here is my current approach: HTML: <form (ngSubmit)="doSomething()"> <table> <thead> <tr>First Name</tr> <tr>Last ...

Connecting an android application to an ASP.NET website

I am currently developing an Android application that includes a form for users to complete. My goal is to send the information entered by the user to an ASP.NET page, where the data will be saved in a database. Once the data is successfully inserted into ...

What is the method for storing a JSON object path in a variable for use in a template?

Trying to fetch data from a lengthy path has proven challenging for me. I attempted to store the path in a variable and incorporate it into the template, but encountered some issues. Could someone assist me with this? Here is what I have tried: My store ...

How to identify generic return type in TypeScript

My goal is to develop a core dialog class that can automatically resolve dialog types and return values based on the input provided. I have made progress in implementing this functionality, but I am facing challenges with handling the return values. Each ...

Angular - Switching Displayed Information

I am currently working with Angular 4 and I am attempting to switch between contenteditable="true" and contenteditable="false" Here is what I have so far: <h1 (dblclick)="edit($event)" contentEditable="true">Double-click Here to edit</h1> Al ...

Discovering if objects possess intersecting branches and devising a useful error notification

I have 2 items that must not share any common features: const translated = { a: { b: { c: "Hello", d: "World" } } }; const toTranslate = { a: { b: { d: "Everybody" } } }; The code ab ...

Ways to specify the T (Generic type) associated with the class

I am working with a class that uses a generic type like this: SomeGenericClass<T>{ constructor(){ } } Within some of the functions, I log messages and want to refer to the current type T of the generic class in my logs. I have attempted t ...

A guide to finding the mean in Angular by utilizing JSON information

import { Component, OnInit } from "@angular/core"; import { MarkService } from "../app/services/marks.service"; @Component({ selector: "app-root", templateUrl: "./app.component.html", styleUrls: ["./app.component.scss"] }) export class AppComp ...

ngx-upload-core and media files

Recently, I started working with the newest release of ngx-resource-core in Angular 7. I'm wondering if there is a method to submit a multipart form when considering that a model could include files or byte arrays? ...

Using Angular to pass a class as a parameter in an HTTP GET request

I am currently working with a class that looks like this: export class CodeTable { public tableId: number; public connectionTable: number; public connectionCode: number; public code: number; ...

AngularJS2 brings a powerful and seamless implementation of indexedDB for efficient

I'm on the hunt for an indexeddb implementation that works seamlessly with Angularjs2. While I stumbled upon this api at https://github.com/gilf/angular2-indexeddb, it appears to be lacking in active development and may not be ready for production use ...

Angular directive problem

Within the module, I have defined a directive but the <div> is not being highlighted as expected. test.directive.ts import { Directive, ElementRef, HostListener, Input } from "@angular/core"; @Directive({ selector: '[test]' }) expor ...

Tips on creating a local database setup to efficiently delete rows during syncing with a server

My current setup involves a local SQLite database that periodically updates from a server. At the start, the local database will be empty and the app will retrieve the entire server database in JSON format, inserting all new rows locally. As time goes on ...

Creating a Typescript interface where one property is dependent on another property

Let's look at an illustration: type Colors = { light: 'EC3333' | 'E91515' dark: '#100F0F' | '140F0F' } interface Palette { colorType: keyof Colors color: Colors[keyof Colors] } Is it possible for the ...

Struggling with the TypeScript generic syntax for the GroupBy function

Struggling to figure out where I'm going wrong with this TypeScript signature after spending some time on it. I've been working on a group by function: const group = <T>(items: T[], fn: (item: T) => T[keyof T]) => { return items.re ...

developed a website utilizing ASP MVC in combination with Angular 2 framework

When it comes to developing the front end, I prefer using Angular 2. For the back end, I stick with Asp MVC (not ASP CORE)... In a typical Asp MVC application, these are the steps usually taken to publish the app: Begin by right-clicking on the project ...