textfield-length-validation

0.1.1 • Public • Published

Text field length validation

This should be used in the following manner:

Install with the command:

npm install --save textfield-length-validation

Then, in your code:

import { lengthValidation } from 'textfield-length-validation';

let isValid = lengthValidation(input, counter, maxCharacters);

Where:

  • input is the input field
  • counter could be a <span> tag to show the character countdown
  • maxCharacters is the maximum number of characters allowed

Example of use

<input type="text" id="input"/>

<div>
    Characters left <span id="textCounter"></span>
</div>
import { lengthValidation } from 'textfield-length-validation';

const input = document.getElementById('input');
const counter = document.getElementById('textCounter');
const maxCharacters = 10;

lengthValidation(input, counter, maxCharacters);

As it returns a boolean, it can be used to disable a submit button.

Package Sidebar

Install

npm i textfield-length-validation

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

2.82 kB

Total Files

3

Last publish

Collaborators

  • nlarrea_