2.1.0 • Published 1 year ago

@taimoorimran/tval v2.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
1 year ago

Logo of t-val

Build Status npm

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!

Installation

Installing the package.

$ npm install @taimoorimran/tval

Usage

// importing the package
    import tval from '@taimoorimran/tval';
// calling the function
    const config = { 
        ...
    }
    console.log(tval('value', config));

Configuration

Length

RuleTypeValueDescription
minLengthint-Length of string should be greater
const config = {
    minLength: 5
}
RuleTypeValueDescription
maxLengthint-Length of string should be lesser
const config = {
    maxLength: 5
}
RuleTypeValueDescription
lengthint-Length of string should be equals to
const config = {
    length: 5
}

Alphabets

RuleTypeValueDescription
allowUpperboolDefault: FalseAllow upper case characters in string - A-Z
const config = {
    characters: {
        allowUpper: // true / false
    }
}
RuleTypeValueDescription
allowLowerboolDefault: FalseAllow lower case characters in string - a-z
const config = {
    characters: {
        allowLower: // true / false
    }
}

Numerals

RuleTypeValueDescription
allowNumericboolDefault: FalseAllow numerals in string - 0-9
const config = {
    allowNumeric: // true / false
}

Space

RuleTypeValueDescription
dontAllowSpaceboolDefault: FalseAllow spaces in string
const config = {
    dontAllowSpace: // true / false
}

Special Characters

RuleTypeValueDescription
allowAllboolDefault: FalseAllow special characters => !, @, #, $, %, ^, &, *
const config = {
    specialCharacters: {
        allowAll: // true / false
    }
}
RuleTypeValueDescription
onlyAllowTheseboolDefault: FalseAdd selective special characters
const config = {
    specialCharacters: {
        onlyAllowThese: '&#_-'
    }
}

Overview

const config = {
    minLength: 1,
    maxLength: 5,
    //OR
    length: 10,
    allowNumeric: // true / false,
    characters: {
        allowUpper: // true / false,
        allowLower: // true / false
    },
    specialCharacters: {
        allowAll: // true / false,
        onlyAllowThese: '&#_-'
    }
}

License

t-val is MIT licensed.

Powered By

Logo of 7ctech

2.1.0

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago