npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tanzanian-phone-validator

v1.1.5

Published

Phone Number Validation for Tanzanian.

Downloads

20

Readme

Tanzanian Phone Number Validation

A simple npm package for validating Tanzanian phone numbers using regular expressions.

Installation

You can install this package via npm:

npm i tanzanian-phone-validator

Example

You can check an example of this library Here.

Here is how it look like:

image

Usage

Use the isValidPhoneNumber function to validate a phone number. It returns true if the phone number is valid and false otherwise.

Use the getPhoneNumberDetails function to get information about a phone number. It returns an object various information about the phone number as shown below:

const results = {
  isValid: true,
  telecomCompanyDetails: {
    prefix: 76,
    company: "Vodacom Tanzania Limited",
    brand: "Vodacom",
    operational: "yes",
  },
};

Usage with validation libraries

Here are some usage examples with different validation libraries:

Using Yup

const yup = require("yup");
import { isValidPhoneNumber } from "tanzanian-phone-validator";

const schema = yup.object({
  phoneNumber: yup
    .string()
    .test("is-tanzanian", "Invalid Tanzanian phone number", (value) => {
      return isValidPhoneNumber(value);
    }),
});

// Example usage
const data = {
  phoneNumber: "+255761234567",
};

schema
  .validate(data)
  .then((validatedData) => {
    console.log("Validation succeeded:", validatedData);
  })
  .catch((error) => {
    console.error("Validation failed:", error.message);
  });

Using Zod

const { z } = require("zod");
import { validateTanzanianPhoneNumber } from "tanzanian-phone-validator";

const schema = z.object({
  phoneNumber: z.string().refine(
    (value) => {
      return isValidPhoneNumber(value);
    },
    {
      message: "Invalid Tanzanian phone number",
    }
  ),
});

// Example usage
const data = {
  phoneNumber: "+255761234567",
};

try {
  const validatedData = schema.parse(data);
  console.log("Validation succeeded:", validatedData);
} catch (error) {
  console.error("Validation failed:", error.message);
}

Direct usage (Node Js)

You can also directly use the isValidPhoneNumber function:

import { validateTanzanianPhoneNumber } from "tanzanian-phone-validator";

const phoneNumber = "+255761234567";

if (isValidPhoneNumber(phoneNumber)) {
  console.log("Valid Tanzanian phone number.");
} else {
  console.log("Invalid Tanzanian phone number.");
}

List of Tanzanian mobile network operators and their prefixes

This table was used to used to create this package. IT can be found in wikipedia (Click here).. Note : this package does not validate for Operators which are not in Operation nor on this table.

| Prefix | Operator | Trading as | Operational[1] | | ------ | ------------------------------------------------- | ---------- | -------------- | | 61 | Viettel Tanzania Limited | halotel | yes | | 62 | Viettel Tanzania Limited | halotel | yes | | 63 | Mkulima African Telecommunication Company Limited | Amotel | no | | 64 | Wiafrica Tanzania Limited | CooTel | no | | 65 | MIC Tanzania Limited | tiGo | yes | | 66 | Smile Communications Tanzania Limited | smile | yes | | 67 | MIC Tanzania Limited | tiGo | yes | | 68 | Airtel Tanzania Limited | airtel | yes | | 69 | Airtel Tanzania Limited | airtel | yes | | 71 | MIC Tanzania Limited | tiGo | yes | | 72 | MO Mobile Holding Limited | | no | | 73 | Tanzania Telecommunications Company Ltd | TTCL | yes | | 74 | Vodacom Tanzania Limited | Vodacom | yes | | 75 | Vodacom Tanzania Limited | Vodacom | yes | | 76 | Vodacom Tanzania Limited | Vodacom | yes | | 77 | MIC Tanzania Limited | tiGo | yes | | 78 | Airtel Tanzania Limited | airtel | yes | | 79 | Benson Informatics Ltd | Smart | no |

License This package is licensed under the MIT License. See the LICENSE..