0.1.1 • Published 1 year ago
textfield-length-validation v0.1.1
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 fieldcounter
could be a<span>
tag to show the character countdownmaxCharacters
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.