checkval

The most versatile validator for Node JS and web browsers.

Showing:

Popularity

Downloads/wk

1

GitHub Stars

9

Maintenance

Last Commit

7yrs ago

Contributors

2

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

checkval

The most versatile validator for Node JS and web browsers.

Usage

Server-side

var checkval = require('checkval');

Client-side

<script type="text/javascript" src="checkval.min.js"></script>

Sintaxis

Returning boolean:

if ( !checkval('email@example.com').email().check() ) {
    console.error('invalid data');
}

Returning boolean (multiple validations):

if ( !checkval().
        add('456457', 'id').numeric().len(5, 10).
        add('email@example.com').email().check() ) {

    console.error('invalid data');
}

Throwing an error:

try {
    
    checkval().
      add('456457', 'id').numeric().len(5, 10).
      add('email@example.com', 'email').email().
    throw();

} catch (err) {
    console.error(err);
}

Getting all errors:

var errors = checkval().
    add('456457', 'id').numeric().len(5, 10).
    add('email@example.com').email().
    errors();

while ( errors.length > 0 ) {
    console.error(errors.pop());
}

Validators

  • alpha() : check if the value contains only letters (a-zA-Z).
  • alphanumeric() : check if the value contains only letters and numbers (a-zA-Z0-9).
  • email() : check if the value is an email.
  • len(min[, max]) : check if the value's length falls in a range.
  • notNull() : check if the value is not null.
  • null() : check if the value is null.
  • integer() : check if the value is an integer (e.g. 345, -81)
  • positiveInt() : check if the value is a positive integer (e.g. 345)
  • numeric() : check if the string contains only a valid integer or decimal number (0-9).
  • date() : check if the string is a valid date.
  • regex(regex[, msg]) : returns true if the value matches the comparison. e.g.: checkval().add("test").regex(/^test$/).check()
  • uuid() : check if the value is a UUID (version 3, 4 or 5).
  • bool() : check if the value is a boolean (strict)
  • array() : check if the value is in a valid array.
  • inArray(values) : check if the value is in a array of allowed values.

Running tests

To run the test suite, first invoke the following command within the project folder, installing the development dependencies:

$ npm install

Then run the tests:

$ npm test

License (MIT)

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial