Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
// @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
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")
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")
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")
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")
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")
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")
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")
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
}