How to use validatorjs - 10 common examples

To help you get started, we’ve selected a few validatorjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LinusBorg / composition-api-demos / src / composables / use-validation.js View on Github external
const validateAll = () => {
    // can we move this outside of the fn?
    const validator = new Validator(modelRef.value, rules)
    console.log('validating')
    valid.value = !dirty.value || validator.passes()
    errors.value = dirty.value && validator.errors.errors
    // console.log(validator.errors)
  }
github Dev-Snippets / java-snippets / js / declarative-validator / src / core / validatorjs.js View on Github external
// @flow
import type { ValidateResponse } from './types';
const Validator = require('validatorjs');
Validator.useLang('zh');

/**
 * Description 自定义校验规则,!本部分是使用了 validatorjs 作为内部实现
 * @param data
 * @param rules
 * @param customMessage
 * @return ValidateResponse
 */
export function validate(
  data: any,
  rules: {
    [string]: string | []
  },
  customMessage: {
    [string]: string
  } = undefined
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
validator.passes(() => {})

var fails: boolean = validator.fails() as boolean
validator.fails(() => {})

var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
var passes: boolean = validator.passes() as boolean
validator.passes(() => {})

var fails: boolean = validator.fails() as boolean
validator.fails(() => {})

var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
var fails: boolean = validator.fails() as boolean
validator.fails(() => {})

var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
var passes: boolean = validator.passes() as boolean
validator.passes(() => {})

var fails: boolean = validator.fails() as boolean
validator.fails(() => {})

var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github DefinitelyTyped / DefinitelyTyped / validatorjs / validatorjs-tests.ts View on Github external
validator.fails(() => {})

var check: boolean = validator.check()

var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")

Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
github nuitcoder / neubbs / src / main / webapp / src / utils / validate.js View on Github external
export const validateLogin = (values, props) => {
  const { intl: { formatMessage } } = props

  const rules = {
    username: 'required|between:3,15|alpha_num',
    password: 'required|between:6,16',
  }
  const messages = {
    'required.username': formatMessage({ id: 'validate.username.required' }),
    'between.username': formatMessage({ id: 'validate.username.between' }),
    'alpha_num.username': formatMessage({ id: 'validate.username.alpha_num' }),
    'required.password': formatMessage({ id: 'validate.password.required' }),
    'between.password': formatMessage({ id: 'validate.password.between' }),
  }
  const validation = new Validator(values, rules, messages)

  const errors = {}
  if (validation.fails()) {
    errors.username = validation.errors.first('username')
    errors.password = validation.errors.first('password')
  }

  return errors
}