1.0.2 • Published 2 years ago
@oz-om/verify-inputs v1.0.2
@oz-om/verify-inputs
A simple functionality to verify user inputs, This library is capable of validating username, email, and password fields based on provided requirements.
instalation
To install this library, run the following command in your terminal:
npm i @oz-om/verify-inputs
or you can download code
Usage
Here's how to use the @oz-om/verify-inputs library in your project:
import inputsValidation from '@oz-om/verify-inputs';
inputsValidation({ name: 'inputName', value: 'inputValue' }, requirements).then(result => {
console.log(result);
});
first paramiter (input)
specific input type and value 1. name : (STRING)
username, email, password
- value: (STRING)
example
{
name:"useranme",
value:"oz-om"
}
second paramiter (requirements)
each input has different requirements:
📌 username input:
{
maxLength: 3,
hasSymbols:false
}
maxLength
: is 3 by default, if value less than 3 it's will return "username length short then ${maxLength}"hasSymbols
: isfalse
by default that's mean the useranme can't include any symbols, if set hasSymbols totrue
then you need to specific what Symbols that if there in username will be validsymbols
: is empty string by default, when to set hasSymbols totrue
then you need to specific symbols in string_-~
example
{
maxLength:4,
hasSymbols: true,
symbols: '_-~'
}
let usernameInput = document.getElementById("usernane");
usernameInput.oninput = () => {
inputsValidation(usernameInput).then(result =>{
console.log(result)
});
}
usernameInput.oninput = () => {
inputsValidation(usernameInput, {
maxLength: 4,
hasSymbols: false
}).then(result => {
console.log(result);
});
}
/*---------------------*/
inputsValidation({name:'username', value:'oz-om'}) // invalid username, its should contain only letters
inputsValidation({
name: 'username',
value: 'oz-om' }, {
maxLength: 4,
hasSymbols: false }).then(result => {
console.log(result);// invalid username, its should contain only letters
});
inputsValidation({
name: 'username',
value: 'oz-om' }, {
maxLength: 4,
hasSymbols: true,
symbols: '_-'
}).then(result => {
console.log(result);// true
});
📌 email input:
no requirements specific reight now example
inputsValidation({name:'email',value:'ozom@mail.com'})
📌 password input:
{
maxLength:8,
upper: true,
symbols: true
}
maxLength
: is 8 by defaultupper
: istrue
by default, password should contain Uppercase letterssymbols
istrue
by default, pssowrd shoukd contain one symbo at least"@#$_&-+(][){}\=^"
example
{
maxLength: 6,
upper: false,
symbols: false
}
let passwordInput = document.querySelector(".passwordInput");
inputsValidation(passwordInput).then(result => {
console.log(result);
});
inputsValidation(passwordInput, {
maxLength: 4,
symbol: false
}).then(result => {
console.log(result);
});
/*---------------------------*/
inputsValidation({
name:'password',
value:'ozom'
}).then(result => {
console.log(result); // invalid password, its should contain more than 8 carachters, one UpperCase, One symbol
});
inputsValidation({
name: 'password',
value: 'ozom' }, {
maxLength: 4,
upper: false,
symbol: false
}).then(result => {
console.log(result); // true
});