Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restricted-input

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restricted-input

Restrict inputs to certain valid characters (e.g. formatting phone or card numbers)

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
263K
decreased by-5.39%
Maintainers
1
Weekly downloads
 
Created

What is restricted-input?

The restricted-input npm package allows developers to restrict the input in HTML input fields based on custom rules. It is useful for enforcing specific formats such as phone numbers, credit card numbers, or any other custom input patterns.

What are restricted-input's main functionalities?

Restrict input to a specific pattern

This feature allows you to restrict the input to a specific pattern. In this example, the input is restricted to a phone number format (999-999-9999).

const RestrictedInput = require('restricted-input');
const inputElement = document.querySelector('#my-input');
new RestrictedInput({
  element: inputElement,
  pattern: '999-999-9999'
});

Custom placeholder character

This feature allows you to set a custom placeholder character. In this example, the placeholder character is set to '_'.

const RestrictedInput = require('restricted-input');
const inputElement = document.querySelector('#my-input');
new RestrictedInput({
  element: inputElement,
  pattern: '999-999-9999',
  placeholder: '_'
});

Dynamic pattern updates

This feature allows you to update the input pattern dynamically. In this example, the pattern is initially set to a phone number format and then updated to a credit card format.

const RestrictedInput = require('restricted-input');
const inputElement = document.querySelector('#my-input');
const restrictedInput = new RestrictedInput({
  element: inputElement,
  pattern: '999-999-9999'
});

// Update the pattern dynamically
restrictedInput.updatePattern('9999-9999-9999-9999');

Other packages similar to restricted-input

Keywords

FAQs

Package last updated on 10 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc