-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.ts
More file actions
28 lines (21 loc) · 754 Bytes
/
validators.ts
File metadata and controls
28 lines (21 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// https://github.com/vuelidate/vuelidate/tree/next/packages/validators
import { email, required /* sameAs, minLength */, helpers } from '@vuelidate/validators/dist/index.esm';
import { unwrap } from './validation';
import { Validator } from './types';
const sameAs = (field) => ({
$validator: (value, context) => value === unwrap(context[field].$model),
$message: `This needs to be the same as the ${field} field.`,
}) as Validator;
const minLength = (length) => ({
$validator: (value) => !helpers.req(value) || helpers.len(value) >= length,
$message: `This field should be at least ${length} long.`,
}) as Validator;
export {
// simple
required,
email,
// complex (depend on args or context)
minLength,
sameAs,
// etc..
};