![Logo of t-val](https://camo.githubusercontent.com/1f76f5b77fc51720ea7bb4a3dcec5a257612aed5b3a6428201ea5eef276b503e/68747470733a2f2f3763746563682e636f6d2f7476616c2d6c6f676f2e706e67)
![npm](https://camo.githubusercontent.com/9d522a3e9f3011e581fc6ef4d33135e0d3fa6d99108d43df8dd566e10ce9e006/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f407461696d6f6f72696d72616e2f7476616c)
t-val is an input validator, can be used with the input field and you can define set of rules to apply on input field.
Here's the Code Sandbox!
Installing the package.
$ npm install @taimoorimran/tval
// importing the package
import tval from '@taimoorimran/tval';
// calling the function
const config = {
...
}
console.log(tval('value', config));
Rule |
Type |
Value |
Description |
minLength |
int |
- |
Length of string should be greater |
const config = {
minLength: 5
}
Rule |
Type |
Value |
Description |
maxLength |
int |
- |
Length of string should be lesser |
const config = {
maxLength: 5
}
Rule |
Type |
Value |
Description |
length |
int |
- |
Length of string should be equals to |
const config = {
length: 5
}
Rule |
Type |
Value |
Description |
allowUpper |
bool |
Default: False |
Allow upper case characters in string - [A-Z] |
const config = {
characters: {
allowUpper: // true / false
}
}
Rule |
Type |
Value |
Description |
allowLower |
bool |
Default: False |
Allow lower case characters in string - [a-z] |
const config = {
characters: {
allowLower: // true / false
}
}
Rule |
Type |
Value |
Description |
allowNumeric |
bool |
Default: False |
Allow numerals in string - [0-9] |
const config = {
allowNumeric: // true / false
}
Rule |
Type |
Value |
Description |
dontAllowSpace |
bool |
Default: False |
Allow spaces in string |
const config = {
dontAllowSpace: // true / false
}
Rule |
Type |
Value |
Description |
allowAll |
bool |
Default: False |
Allow special characters => [!, @, #, $, %, ^, &, *] |
const config = {
specialCharacters: {
allowAll: // true / false
}
}
Rule |
Type |
Value |
Description |
onlyAllowThese |
bool |
Default: False |
Add selective special characters |
const config = {
specialCharacters: {
onlyAllowThese: '&#_-'
}
}
const config = {
minLength: 1,
maxLength: 5,
//OR
length: 10,
allowNumeric: // true / false,
characters: {
allowUpper: // true / false,
allowLower: // true / false
},
specialCharacters: {
allowAll: // true / false,
onlyAllowThese: '&#_-'
}
}
t-val is MIT licensed.
![Logo of 7ctech](https://camo.githubusercontent.com/cf36d53724a4c44b0c4eda7ac8a70a9902740e908300df5a8532075eee176c55/68747470733a2f2f3763746563682e636f6d2f6c6f676f2d736d616c6c2d322e706e67)