cb-valid
It is very easy to implement in your project. Allows the use of non-decorator based validation. Use validator.js internally to perform the validation.
Installation
npm install cb-valid --save
Note: Please use at least npm@6 when using cb-valid. From npm@6 the dependency tree is flattened, which is required by
cb-valid
to function properly.
Usage
// Valid for typescript // Valid for javascript vanilla // We declare a test string to validate // We clearly know that the variable testValue does not have a valid email!// why will you show us the messages entered! // Here you will add the validation you need /** * @Return * */ /*{ status: false, messages: [ "Email is invalid !", "Email needs a maximum of 10 characters!" ]}*/
Passing options
Some functions require a data
parameter
Validation errors
The cb-valid
method returns an array ofValidationError
objects. Each ValidationError
is:
Manual validation
There are several method exist in the Validator that allows to perform non-decorator based validation:
; // Validation methods; Lengthvalue, // minLengthvalue, maxLengthvalue, isEmailvalue // Checks if the string is an email. isURLvalue // Checks if the string is an url. isFQDNvalue // Checks if the string is a fully qualified domain name (e.g. domain.com). isEmptyvalue // Checks if given value is empty (=== '', === null, === undefined). isNotEmptyvalue // Checks if given value is not empty (!== '', !== null, !== undefined). isAsciivalue // Checks if the string contains ASCII chars only. isBase64value // Checks if a string is base64 encoded. isCreditCardvalue // Checks if the string is a credit card. isCurrencyvalue // Checks if the string is a valid currency amount. isDecimalvalue // Checks if the string is a valid decimal value. isFullWidthvalue // Checks if the string contains any full-width chars. isHexadecimalvalue // Checks if the string is a hexadecimal number. isHexColorvalue // Checks if the string is a hexadecimal color. isISINvalue // Checks if the string is an ISIN (stock/security identifier). isISO31661Alpha2value // Check if the string is a valid ISO 3166-1 alpha-2 isISO31661Alpha3value // Check if the string is a valid ISO 3166-1 alpha-3 isISO8601value // Checks if the string is a valid ISO 8601 date. Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29. isISSNvalue // Checks if the string is a ISSN. isJSONvalue // Checks if the string is valid JSON (note: uses JSON.parse). isJWTvalue // Checks if the string is valid JWT. isLatLongvalue // Checks if the string is a valid latitude-longitude coordinate in the format lat,long isLowercasevalue // Checks if the string is lowercase. isMACAddressvalue // Checks if the string is a MAC Address. isMongoIdvalue // Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId. isMultibytevalue // Checks if the string contains one or more multibyte chars. isPortvalue // Check if the string is a valid port number. isSurrogatePairvalue // Checks if the string contains any surrogate pairs chars. isUppercasevalue // Checks if the string is uppercase. isVariableWidthvalue // Checks if the string contains variable-width chars.
Backers
Stay in touch
- Author Yoni Calsin
- Twitter Yoni Calsin
Release notes
See information about breaking changes and release notes.
cb-valid v0.0.1
License
Nest is MIT licensed.