Socket
Socket
Sign inDemoInstall

composite-phone-number

Package Overview
Dependencies
3
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    composite-phone-number

Take an html input field like:


Version published
Maintainers
1
Created

Readme

Source

Composite Phone Number widget

Take an html input field like:

<label>
	phone number
	<input id="phone" name="phone" type="text" />
</label>

And creates equivalent html like:

<div class="phone-number-parts">
		(<input class="phone-area-code" aria-label="phone number area code" type="text" size="3" maxlength="3" pattern="[0-9]{3}">) 
		<input class="phone-prefix" aria-label="phone number prefix" type="text" size="3" maxlength="3" pattern="[0-9]{3}"> 
		-
		<input class="phone-line-number" aria-label="phone number line number" size="4" maxlength="4" type="text" pattern="[0-9]{4}"> 
</div>

It makes the original field a hidden type, preserves the "requiredness" of the original field, attempts to extract the label of the original field and use it for the component fields. It also populates the new sub-fields with the appropriate values from the original field

It creates listeners to update the original field with the composite value of the sub-fields eery time a sub field changes. It also attempts to move the user from area code to prefix to line number when they have entered the correct number of digits.

Install

Install like:

npm install composite-phone-number

Usage

Use like:

const compositePhoneNumber = require('composite-phone-number')
compositePhoneNumber(document.querySelector('#phone'))

Just use the form normally from then.

FAQs

Last updated on 08 Jun 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc