Validator: JavaScript Validation Framework for Node.js and Browsers

Validator is a JavaScript validation framework designed for both Node.js and browser environments. This library does not include built-in validation functions but allows for the addition of custom plugins. For example, the following code adds a 'required' validation plugin:

const fs = require('fs');
const Validator = require('./../index');

Validator.addPlugin({
  tagName: 'required',
  execFunc(field, value, opts) {
    if (opts.tagValue === true && (value == undefined || value == null || value == '')) {
      return false;
    }
    return true;
  }
});

const v = new Validator({});

This example shows how to extend the library with a custom validation rule.

zip 文件大小:771.04KB