A simple functionality to verify user inputs, This library is capable of validating username, email, and password fields based on provided requirements.
To install this library, run the following command in your terminal:
npm i @oz-om/verify-inputs
or you can download code
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);
});
specific input type and value
- name : (STRING)
username, email, password
- value: (STRING)
example
{
name:"useranme",
value:"oz-om"
}
each input has different requirements:
{ 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
});
no requirements specific reight now example
inputsValidation({name:'email',value:'ozom@mail.com'})
{ 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
});