t-val is an input validator, can be used with the input field and you can define set of rules to apply on field.
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: minLength Type: int Value: - Description: Length of string should be greater
const config = {
minLength: 5
}
Rule: maxLength Type: int Value: - Description: Length of string should be lesser
const config = {
maxLength: 5
}
Rule: length Type: int Value: - Description: Length of string should be equals to
const config = {
length: 5
}
Rule: allowUpper Type: bool Value: Default: False Description: Allow upper case characters in string - [A-Z]
const config = {
characters: {
allowUpper: // true / false
}
}
Rule: allowLower Type: bool Value: Default: False Description: Allow lower case characters in string - [a-z]
const config = {
characters: {
allowLower: // true / false
}
}
Rule: allowNumeric Type: bool Value: Default: False Description: Allow numerals in string - [0-9]
const config = {
allowNumeric: // true / false
}
Rule: dontAllowSpace Type: bool Value: Default: False Description: Allow spaces in string
const config = {
dontAllowSpace: // true / false
}
Rule: allowAll Type: bool Value: Default: False Description: Allow special characters => [!, @, #, $, %, ^, &, *]
const config = {
specialCharacters: {
allowAll: // true / false
}
}
Rule: onlyAllowThese Type: bool Value: Default: False Description: 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.