示例#1
0
validate.validators.string = function(value) {
  if(value) {
    if(!validate.isString(value)) {
      return "is not a string";
    }
  }
  return null;
}
示例#2
0
Validators.prototype.isString = function(obj) {
  if(typeof obj !== 'undefined' && obj !== null) {
    var val = validate.isString(obj);
    if (!val) {
      return util.constructValidationMessage(val, "Type is not a string");
    }
  }
  return true;
};
                to: function (value, attributes, attributeName, options, constraints) {
                    if (validate.isEmpty(value)) {
                        return {
                            presence: {message: "is required"}
                        };
                    }

                    if (!validate.isArray(value) && !validate.isString(value)) {
                        return {
                            format: "must be a string or an array strings (phone numbers)"
                        };
                    }

                    if (validate.isString(value)) {
                        // TODO: Validate number format
                        let isInvalid = false;
                        if (isInvalid) {
                            return {
                                format: "must be a valid phone number"
                            };
                        }
                    }

                    if (validate.isArray(value)) {
                        let foundInvalid = false;
                        value.forEach(function (phone) {
                            // TODO: Validate number format
                        });
                        if (foundInvalid) {
                            return {
                                format: "must NOT contain invalid phone number"
                            }
                        }
                    }

                    return null;
                },
// @flow

import validate from 'validate.js';

/* Trivial case */

// $ExpectError
validate.foo();

validate.isString(true)
validate.isArray(true)

validate({
}, {
  foofield: {
    required: true,
  }
}, {
  format: 'grouped'
})

/* validate.validators */

validate.validators.new_validator = () => {};

// $ExpectError
validate.validators.new_validator = true;