0.1.1 • Published 3 years 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-validationThen, in your code:
import { lengthValidation } from 'textfield-length-validation';
let isValid = lengthValidation(input, counter, maxCharacters);Where:
inputis the input fieldcountercould be a<span>tag to show the character countdownmaxCharactersis 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.