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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@masters-ws/react-country-phone-input-mask

v1.1.1

Published

A smart, highly customizable phone number input with automatic formatting and country selection for React and Next.js.

Downloads

60

Readme

@masters-ws/react-country-phone-input-mask

A smart, highly customizable phone number input component for React and Next.js with automatic formatting, country selection, high-quality flags, and built-in validation.

NPM Version

Features

  • 🌍 Global Support: Masks and validates phone numbers for all countries seamlessly using libphonenumber-js.
  • Built-in Validation: Real-time validation for phone length and required fields.
  • 🏳️ High-Quality Flags: Uses real images (FlagCDN) for flags to guarantee they render beautifully on all operating systems.
  • 🇸🇾 Syrian Revolution Flag Support: Built-in exception for Syria (SY) to render the Syrian Revolution flag.
  • Next.js & SSR Ready: Completely compatible with Server-Side Rendering.
  • 🎨 Fully Customizable: Add your own CSS classes (or Tailwind CSS) to style the input, dropdown, and container.
  • 🌙 Dark Mode Support: Minimal default styles that automatically adapt to dark mode.

Installation

npm install @masters-ws/react-country-phone-input-mask
# or
yarn add @masters-ws/react-country-phone-input-mask

Basic Usage

import React, { useState } from 'react';
import { PhoneInput, PhoneMeta } from '@masters-ws/react-country-phone-input-mask';
import '@masters-ws/react-country-phone-input-mask/style.css';

export default function App() {
  const [phone, setPhone] = useState('');

  return (
    <div style={{ padding: '2rem' }}>
      <PhoneInput
        defaultCountry="SA"
        value={phone}
        onChange={(val) => setPhone(val)}
        validate={true} // Enable built-in validation
        errorMessage="Please enter a valid phone number"
      />
    </div>
  );
}

Validation & Error Handling

The component supports three ways to handle validation:

  1. Automatic Validation: Pass validate={true} to show a red border and error message if the number is incomplete or empty (after the field is touched).
  2. Custom Error Messages: Use errorMessage="Your custom message".
  3. External Control: Use error={true} to force the error state from outside (perfect for react-hook-form or formik).
// Example with external error (e.g. from react-hook-form)
<PhoneInput
  error={!!errors.phone}
  errorMessage={errors.phone?.message}
  {...register('phone')}
/>

Props

| Prop | Type | Default | Description | |---|---|---|---| | value | string | '' | The controlled value of the input. | | onChange | (value: string, meta: PhoneMeta) => void | undefined | Callback fired when the value or country changes. | | defaultCountry | CountryCode | 'SA' | Default selected country code (ISO 2-letter). | | preferredCountries | CountryCode[] | [] | Array of country codes to pin to the top. | | validate | boolean | false | Enable real-time digit count validation. | | errorMessage | string | 'رقم الهاتف غير صحيح' | Custom message to show on error. | | error | boolean | false | Force the error state manually. | | containerClassName | string | '' | CSS class for the root container. | | inputClassName | string | '' | CSS class for the input element. | | buttonClassName | string | '' | CSS class for the country button. | | dropdownClassName | string | '' | CSS class for the dropdown. |

The PhoneMeta Object

interface PhoneMeta {
  countryCode?: CountryCode; // e.g. "SA"
  isValid: boolean;          // true if format matches country rules
  nationalNumber?: string;   // number without dial code
  formattedNumber?: string;  // fully formatted international string
}

License

MIT