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

phonevalidator

v1.1.4

Published

Phone Validator is a Javascript object that helps you validate a phone number written in an international format even if it contains ther characters that are not numeric. It recognizes Country Code, Country Name, Country Continent, and other useful inform

Downloads

22

Readme

PhoneValidator

Get international phone number informations

Getting Started

Phone Validator is a Javascript object that helps you validate a phone number written in an international format even if it contains other characters that are not numeric. It recognizes Country Code, Country Name, Country Continent, and other useful information. It's also a full-featured object and have persistent information.

Built in

Phone Validator is built under Javascript without any dependency. It can be used wherever it is necessary to do a verification of the telephone number. It can also be used to get information about the current location of the user after checking the phone

Installing

CDN Integration

Version Spec
<script type="text/javscript" src="https://unpkg.com/[email protected]/phone.validator.js"></scirpt>
Latest Version
<script type="text/javscript" src="https://unpkg.com/phonevalidator/phone.validator.min.js"></script>

Warning: When using the cdn link, you must change the default flag directory to use the country flag link

<script>
  PhoneValidator.useDefaults({},{flagLink:"https://unpkg.com/[email protected]/flags/$1.$2"});
</script>

NPM Integration

Command
npm install --save phonevalidator
Integrate
<script type="text/javscript" src="./node_modules/phonevalidator/phone.validator.min.js"></script>
<script type="text/javscript"> 
  PhoneValidator.useDefaults({},{flagLink:"./node_modules/phonevalidator/flags/$1.$2"});
</script>

Local Repository

Download Phone Validator Git Repository
Git command or download directly from github with this link
git clone https://github.com/niniverloer/phonevalidator.git
Integrate
<script type="text/javscript" src="./path_to_phonevalidator/phone.validator.min.js"></script>
<script type="text/javscript"> 
  PhoneValidator.useDefaults({},{flagLink:"./path_to_phonevalidator/flags/$1.$2"});
</script>

Basic Usage

Get the phone number from a string (even if it's invalid)

  PhoneValidator.init("<string>").val()

i.e:

  PhoneValidator.init("ehfu00agufga23673j--00023848479dfaii").val()

Returns: +23673000238484 which is an invalid phone number

  PhoneValidator.init("(+380) 630-293-53-2").val()

Returns: +380630293532 which is a valid phone number

Note: PhoneValidator recognize 2 international characters 00 and +

Validity of a phone number

PhoneValidator deals with the phone format of all countries in the world to verify if it's a valid phone number

PhoneValidator.init("dsafngjaiodfjajdaoaa").isValid()

Returns: false

PhoneValidator.init("ehfu00agufga23673j--00023848479dfaii").val()

Returns: +23673000238484

PhoneValidator.init("+23673000238484").isValid()

Returns: false

PhoneValidator.init("ehfu00agufga23673j--0002333dfaii").isValid()

Returns: true Because PhoneValidator.init("ehfu00agufga23673j--0002333dfaii").val() Returns +236730002333 which is a valid Central African Republic phone number format

PhoneValidator.init(" +1 671-477-8355").isValid()

Returns : true

Get the phone country code

PhoneValidator.init("<string>")["process"].countryCode

i.e:

  PhoneValidator.init(" +1 671-477-8355")["process"].countryCode

Returns: GU

Get the phone country name

PhoneValidator.init("<string>")["process"].countryName

i.e:

PhoneValidator.init(" +1 671-477-8355")["process"].countryName

Returns: Guam

Get the phone continent of the country

PhoneValidator.init("<string>")["process"].countryContinent

i.e:

  PhoneValidator.init(" +1 671-477-8355")["process"].countryContinent

Returns: OCEANIA

Get the phone country flag image link

  PhoneValidator.init("<string>")["process"].countryFlag

Make sure your country's flag directory contains a correct value, See how to Integrate PhoneValidator in your current project in the previous topic

i.e:

  PhoneValidator.init(" +1 671-477-8355")["process"].countryFlag

Returns: https://unpkg.com/[email protected]/flags/gu.svg You can also change the country's flag directory by this way

  PhoneValidator.init("<string>",{},{flagLink:"<flag_directory>"})["process"].countryFlag

i.e:

  PhoneValidator.init(" +1 671-477-8355",{},{flagLink:"./assets/js/phonevalidator/flags/$1.$2"})["process"].countryFlag

Returns: ./assets/js/phonevalidator/flags/gu.svg this method doesn't change default country's flag directory

Get the international country code in phone number format

  PhoneValidator.init("<string>")["process"].countryContinent

i.e:

  PhoneValidator.init("(+1 671)-477-8355")["process"].countryPhoneCode

Returns: 1671

Get the suscriber number

  PhoneValidator.init("<string>")["process"].suscriberNumber

i.e:

  PhoneValidator.init("+380-63-0293-532")["process"].suscriberNumber

Returns: 630293532

Get the valid phone number

  PhoneValidator.init("<string>")["process"].phoneNumber

i.e:

  PhoneValidator.init("+380-63-0293-532")["process"].phoneNumber

Returns: +380630293532

Working with Phone Validator Events

Phone Validator Events must be added before the initialization

When the string doesn't contains a valid phone number

PhoneValidator.addEventListener("invalid_number",function(number){
  // number can be a invalid phone number, null or an empty string
  if(number){
    console.log("Phone Number :"+number+" doesn't match any country phone format")
  }else{
    console.log("Please input a valid number")
  }
});

Get the fixed number before getting extra information

PhoneValidator.addEventListener("before_initialized",function(number){
  console.log("Fixed Number : ",number)
});

When the phone number validation is finished

PhoneValidator.addEventListener("all_got",function(process){
  console.log("Country Name : ",process.countryName)
});

Author

David Niverloer